From 850ee4ba4edbeba1c77685e5cd4f95e5589cf392 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 12 Feb 2004 20:03:53 +0000 Subject: [PATCH] Authors: David Hammerton , Mike McCormack Completed PeekNamedPipe implementation. --- dlls/kernel/sync.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/dlls/kernel/sync.c b/dlls/kernel/sync.c index b0ca5ea0b76..6a40c0039ab 100644 --- a/dlls/kernel/sync.c +++ b/dlls/kernel/sync.c @@ -32,6 +32,9 @@ #ifdef HAVE_SYS_POLL_H #include #endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif #include #include @@ -1117,13 +1120,26 @@ BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer, return FALSE; } } - wine_server_release_fd( hPipe, fd ); TRACE(" 0x%08x bytes available\n", avail ); - if (!lpvBuffer && lpcbAvail) - { - *lpcbAvail= avail; - return TRUE; - } + ret = TRUE; + if (lpcbAvail) + *lpcbAvail = avail; + if (lpcbRead) + *lpcbRead = 0; + if (avail && lpvBuffer) + { + int readbytes = (avail < cbBuffer) ? avail : cbBuffer; + readbytes = recv(fd, lpvBuffer, readbytes, MSG_PEEK); + if (readbytes < 0) + { + WARN("failed to peek socket (%d)\n", errno); + ret = FALSE; + } + else if (lpcbRead) + *lpcbRead = readbytes; + } + wine_server_release_fd( hPipe, fd ); + return ret; #endif /* defined(FIONREAD) */ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);