Alexandre Julliard : server: Set the specified in/ out buffer sizes on named pipes using SO_SND/RCVBUF.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Jan 15 07:43:02 CST 2007


Module: wine
Branch: master
Commit: 1db223954fa96abbc04e5ff6766eafa9603e669b
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1db223954fa96abbc04e5ff6766eafa9603e669b

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Jan 12 20:59:22 2007 +0100

server: Set the specified in/out buffer sizes on named pipes using SO_SND/RCVBUF.

---

 dlls/kernel32/tests/pipe.c |   22 ++++++++++++++++++++++
 server/named_pipe.c        |   11 +++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c
index c0d0abe..6da65a0 100644
--- a/dlls/kernel32/tests/pipe.c
+++ b/dlls/kernel32/tests/pipe.c
@@ -754,6 +754,8 @@ static void test_CreatePipe(void)
     HANDLE piperead, pipewrite;
     DWORD written;
     DWORD read;
+    DWORD i, size;
+    BYTE *buffer;
     char readbuf[32];
 
     pipe_attr.nLength = sizeof(SECURITY_ATTRIBUTES); 
@@ -764,6 +766,8 @@ static void test_CreatePipe(void)
     ok(written == sizeof(PIPENAME), "Write to anonymous pipe wrote %d bytes\n", written);
     ok(ReadFile(piperead,readbuf,sizeof(readbuf),&read, NULL), "Read from non empty pipe failed\n");
     ok(read == sizeof(PIPENAME), "Read from  anonymous pipe got %d bytes\n", read);
+    ok(CloseHandle(pipewrite), "CloseHandle for the write pipe failed\n");
+    ok(CloseHandle(piperead), "CloseHandle for the read pipe failed\n");
 
     /* Now write another chunk*/
     ok(CreatePipe(&piperead, &pipewrite, &pipe_attr, 0) != 0, "CreatePipe failed\n");
@@ -775,6 +779,24 @@ static void test_CreatePipe(void)
     ok(read == sizeof(PIPENAME), "Read from  anonymous pipe got %d bytes\n", read);
     /* But now we need to get informed that the pipe is closed */
     ok(ReadFile(piperead,readbuf,sizeof(readbuf),&read, NULL) == 0, "Broken pipe not detected\n");
+    ok(CloseHandle(piperead), "CloseHandle for the read pipe failed\n");
+
+    /* Try bigger chunks */
+    size = 32768;
+    buffer = HeapAlloc( GetProcessHeap(), 0, size );
+    for (i = 0; i < size; i++) buffer[i] = i;
+    ok(CreatePipe(&piperead, &pipewrite, &pipe_attr, size) != 0, "CreatePipe failed\n");
+    ok(WriteFile(pipewrite, buffer, size, &written, NULL), "Write to anonymous pipe failed\n");
+    ok(written == size, "Write to anonymous pipe wrote %d bytes\n", written);
+    /* and close the write end, read should still succeed*/
+    ok(CloseHandle(pipewrite), "CloseHandle for the Write Pipe failed\n");
+    memset( buffer, 0, size );
+    ok(ReadFile(piperead, buffer, size, &read, NULL), "Read from broken pipe withe with pending data failed\n");
+    ok(read == size, "Read from  anonymous pipe got %d bytes\n", read);
+    for (i = 0; i < size; i++) ok( buffer[i] == (BYTE)i, "invalid data %x at %x\n", buffer[i], i );
+    /* But now we need to get informed that the pipe is closed */
+    ok(ReadFile(piperead,readbuf,sizeof(readbuf),&read, NULL) == 0, "Broken pipe not detected\n");
+    ok(CloseHandle(piperead), "CloseHandle for the read pipe failed\n");
 }
 
 START_TEST(pipe)
diff --git a/server/named_pipe.c b/server/named_pipe.c
index 9077c58..173290f 100644
--- a/server/named_pipe.c
+++ b/server/named_pipe.c
@@ -776,6 +776,17 @@ DECL_HANDLER(open_named_pipe)
             if ((res != -1) && is_overlapped( server->options ))
                 res = fcntl( fds[0], F_SETFL, O_NONBLOCK );
 
+            if (pipe->insize)
+            {
+                setsockopt( fds[0], SOL_SOCKET, SO_RCVBUF, &pipe->insize, sizeof(pipe->insize) );
+                setsockopt( fds[1], SOL_SOCKET, SO_RCVBUF, &pipe->insize, sizeof(pipe->insize) );
+            }
+            if (pipe->outsize)
+            {
+                setsockopt( fds[0], SOL_SOCKET, SO_SNDBUF, &pipe->outsize, sizeof(pipe->outsize) );
+                setsockopt( fds[1], SOL_SOCKET, SO_SNDBUF, &pipe->outsize, sizeof(pipe->outsize) );
+            }
+
             client->fd = create_anonymous_fd( &pipe_client_fd_ops,
                                             fds[1], &client->obj );
             server->fd = create_anonymous_fd( &pipe_server_fd_ops,




More information about the wine-cvs mailing list