This ensures instances created first will be connected to first.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=41670 Signed-off-by: Huw Davies huw@codeweavers.com --- dlls/kernel32/tests/pipe.c | 38 ++++++++++++++++++++++++++++++++++++++ server/named_pipe.c | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c index 5bf27fac90..5dc6ace731 100644 --- a/dlls/kernel32/tests/pipe.c +++ b/dlls/kernel32/tests/pipe.c @@ -3671,6 +3671,43 @@ static void test_namedpipe_session_id(void) CloseHandle(server); }
+static void test_multiple_instances(void) +{ + HANDLE server[2], client; + int i; + BOOL ret; + OVERLAPPED ov; + + for (i = 0; i < ARRAY_SIZE(server); i++) + { + server[i] = CreateNamedPipeA(PIPENAME, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, + PIPE_READMODE_BYTE | PIPE_WAIT, 2, 1024, 1024, + NMPWAIT_USE_DEFAULT_WAIT, NULL); + ok(server[i] != INVALID_HANDLE_VALUE, "got invalid handle\n"); + } + + client = CreateFileA(PIPENAME, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); + ok(client != INVALID_HANDLE_VALUE, "got invalid handle\n"); + + /* Show that this has connected to server[0] not server[1] */ + + memset(&ov, 0, sizeof(ov)); + ret = ConnectNamedPipe(server[1], &ov); + ok(ret == FALSE, "got %d\n", ret); + ok(GetLastError() == ERROR_IO_PENDING, "got %d\n", GetLastError()); + + memset(&ov, 0, sizeof(ov)); + ret = ConnectNamedPipe(server[0], &ov); + ok(ret == FALSE, "got %d\n", ret); + ok(GetLastError() == ERROR_PIPE_CONNECTED, "got %d\n", GetLastError()); + + DisconnectNamedPipe(server[1]); + DisconnectNamedPipe(server[0]); + CloseHandle(client); + CloseHandle(server[1]); + CloseHandle(server[0]); +} + START_TEST(pipe) { char **argv; @@ -3736,4 +3773,5 @@ START_TEST(pipe) test_TransactNamedPipe(); test_namedpipe_process_id(); test_namedpipe_session_id(); + test_multiple_instances(); } diff --git a/server/named_pipe.c b/server/named_pipe.c index 101ff632b9..9e3303259f 100644 --- a/server/named_pipe.c +++ b/server/named_pipe.c @@ -1162,7 +1162,7 @@ static struct pipe_server *create_pipe_server( struct named_pipe *pipe, unsigned server->pipe_end.server_pid = get_process_id( current->process ); init_async_queue( &server->listen_q );
- list_add_head( &pipe->servers, &server->entry ); + list_add_tail( &pipe->servers, &server->entry ); if (!(server->pipe_end.fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->pipe_end.obj, options ))) { release_object( server );