Codebase list libuv1 / 34768a7
win: fix replacing pipe handle for pipe servers On Windows we create multiple pipe handles (system handles) which are attached to pending accept requests. Each of these will take turns in replacing the reference in handle->handle, so make sure we allow for that **only** for pipe servers. PR-URL: https://github.com/libuv/libuv/pull/488 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Saúl Ibarra Corretgé 8 years ago
5 changed file(s) with 110 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
185185 test/test-ping-pong.c \
186186 test/test-pipe-bind-error.c \
187187 test/test-pipe-connect-error.c \
188 test/test-pipe-connect-multiple.c \
188189 test/test-pipe-connect-prepare.c \
189190 test/test-pipe-getsockname.c \
190191 test/test-pipe-sendmsg.c \
253253 DWORD current_mode = 0;
254254 DWORD err = 0;
255255
256 if (handle->handle != INVALID_HANDLE_VALUE)
256 if (!(handle->flags & UV_HANDLE_PIPESERVER) &&
257 handle->handle != INVALID_HANDLE_VALUE)
257258 return UV_EBUSY;
258259
259260 if (!SetNamedPipeHandleState(pipeHandle, &mode, NULL, NULL)) {
122122 TEST_DECLARE (pipe_bind_error_addrinuse)
123123 TEST_DECLARE (pipe_bind_error_addrnotavail)
124124 TEST_DECLARE (pipe_bind_error_inval)
125 TEST_DECLARE (pipe_connect_multiple)
125126 TEST_DECLARE (pipe_listen_without_bind)
126127 TEST_DECLARE (pipe_connect_bad_name)
127128 TEST_DECLARE (pipe_connect_to_file)
475476 TEST_ENTRY (pipe_bind_error_addrinuse)
476477 TEST_ENTRY (pipe_bind_error_addrnotavail)
477478 TEST_ENTRY (pipe_bind_error_inval)
479 TEST_ENTRY (pipe_connect_multiple)
478480 TEST_ENTRY (pipe_listen_without_bind)
479481 TEST_ENTRY (pipe_getsockname)
480482 TEST_ENTRY (pipe_getsockname_abstract)
0 /* Copyright (c) 2015 Saúl Ibarra Corretgé <saghul@gmail.com>.
1 * All rights reserved.
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 * IN THE SOFTWARE.
20 */
21
22 #include "uv.h"
23 #include "task.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26
27
28 static int connection_cb_called = 0;
29 static int connect_cb_called = 0;
30
31 #define NUM_CLIENTS 4
32
33 typedef struct {
34 uv_pipe_t pipe_handle;
35 uv_connect_t conn_req;
36 } client_t;
37
38 static uv_pipe_t server_handle;
39 static client_t clients[NUM_CLIENTS];
40 static uv_pipe_t connections[NUM_CLIENTS];
41
42
43 static void connection_cb(uv_stream_t* server, int status) {
44 int r;
45 uv_pipe_t* conn;
46 ASSERT(status == 0);
47
48 conn = &connections[connection_cb_called];
49 r = uv_pipe_init(server->loop, conn, 0);
50 ASSERT(r == 0);
51
52 r = uv_accept(server, (uv_stream_t*)conn);
53 ASSERT(r == 0);
54
55 if (++connection_cb_called == NUM_CLIENTS &&
56 connect_cb_called == NUM_CLIENTS) {
57 uv_stop(server->loop);
58 }
59 }
60
61
62 static void connect_cb(uv_connect_t* connect_req, int status) {
63 ASSERT(status == 0);
64 if (++connect_cb_called == NUM_CLIENTS &&
65 connection_cb_called == NUM_CLIENTS) {
66 uv_stop(connect_req->handle->loop);
67 }
68 }
69
70
71 TEST_IMPL(pipe_connect_multiple) {
72 int i;
73 int r;
74 uv_loop_t* loop;
75
76 loop = uv_default_loop();
77
78 r = uv_pipe_init(loop, &server_handle, 0);
79 ASSERT(r == 0);
80
81 r = uv_pipe_bind(&server_handle, TEST_PIPENAME);
82 ASSERT(r == 0);
83
84 r = uv_listen((uv_stream_t*)&server_handle, 128, connection_cb);
85 ASSERT(r == 0);
86
87 for (i = 0; i < NUM_CLIENTS; i++) {
88 r = uv_pipe_init(loop, &clients[i].pipe_handle, 0);
89 ASSERT(r == 0);
90 uv_pipe_connect(&clients[i].conn_req,
91 &clients[i].pipe_handle,
92 TEST_PIPENAME,
93 connect_cb);
94 }
95
96 uv_run(loop, UV_RUN_DEFAULT);
97
98 ASSERT(connection_cb_called == NUM_CLIENTS);
99 ASSERT(connect_cb_called == NUM_CLIENTS);
100
101 MAKE_VALGRIND_HAPPY();
102 return 0;
103 }
325325 'test/test-ping-pong.c',
326326 'test/test-pipe-bind-error.c',
327327 'test/test-pipe-connect-error.c',
328 'test/test-pipe-connect-multiple.c',
328329 'test/test-pipe-connect-prepare.c',
329330 'test/test-pipe-getsockname.c',
330331 'test/test-pipe-sendmsg.c',