server: Add new pipe servers to the end of the servers list.

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>
Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2019-02-26 11:06:25 +00:00 committed by Alexandre Julliard
parent 22b304fd1d
commit e4ca5dbec0
2 changed files with 39 additions and 1 deletions

View File

@ -3671,6 +3671,43 @@ static void test_namedpipe_session_id(void)
CloseHandle(server); 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) START_TEST(pipe)
{ {
char **argv; char **argv;
@ -3736,4 +3773,5 @@ START_TEST(pipe)
test_TransactNamedPipe(); test_TransactNamedPipe();
test_namedpipe_process_id(); test_namedpipe_process_id();
test_namedpipe_session_id(); test_namedpipe_session_id();
test_multiple_instances();
} }

View File

@ -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 ); server->pipe_end.server_pid = get_process_id( current->process );
init_async_queue( &server->listen_q ); 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 ))) if (!(server->pipe_end.fd = alloc_pseudo_fd( &pipe_server_fd_ops, &server->pipe_end.obj, options )))
{ {
release_object( server ); release_object( server );