test: add test for win uds

This commit is contained in:
reito 2025-01-20 00:43:15 +08:00
parent 6d62cf562c
commit 3c56c48a2d
3 changed files with 62 additions and 11 deletions

View File

@ -882,7 +882,8 @@ int uv_pipe_bind2(uv_pipe_t* handle,
handle->pipe.serv.pending_instances = default_pending_pipe_instances;
}
if (handle->flags & UV_HANDLE_WIN_UDS_PIPE) {
if (use_uds_pipe) {
handle->flags |= UV_HANDLE_WIN_UDS_PIPE;
/* Only use 1 pending instance when use unix domain socket, cause
* call AcceptEx multiple times seems result in multiple accept events.
* Not the expected queue behavior, that only one of them is triggered. */
@ -921,7 +922,6 @@ int uv_pipe_bind2(uv_pipe_t* handle,
#if defined(UV__ENABLE_WIN_UDS_PIPE)
if (use_uds_pipe) {
handle->flags |= UV_HANDLE_WIN_UDS_PIPE;
int uds_err = pipe_alloc_accept_unix_domain_socket(
loop, handle, &handle->pipe.serv.accept_reqs[0], handle->pathname, TRUE);
if (uds_err) {
@ -1079,6 +1079,9 @@ int uv_pipe_connect2(uv_connect_t* req,
#if defined(UV__ENABLE_WIN_UDS_PIPE)
if (use_uds_pipe) {
/* Set flag indicates it is a unix domain socket; */
handle->flags |= UV_HANDLE_WIN_UDS_PIPE;
/* https://devblogs.microsoft.com/commandline/af_unix-comes-to-windows/ */
/* a null-terminated UTF-8 file system path */
if (flags & UV_PIPE_NO_TRUNCATE)
@ -1182,9 +1185,6 @@ int uv_pipe_connect2(uv_connect_t* req,
}
}
/* Set flag indicates it is a unix domain socket; */
handle->flags |= UV_HANDLE_WIN_UDS_PIPE;
/* Since we use IOCP, we can't set value to u.connect.pipeHandle
* as it will be rewritten by the result of IOCP. Thus, we set the socket
* to uds_socket (reuse the `name`) and set it to pipeHandle later at req
@ -2641,12 +2641,14 @@ void uv__process_pipe_connect_req(uv_loop_t* loop, uv_pipe_t* handle,
/* IOCP overwrites the connect.pipeHandle, so workaround here. */
req->u.connect.pipeHandle = (HANDLE) req->u.connect.uds_socket;
/* If it is unix domain handle, the event comes from ConnectEx IOCP. */
setsockopt((SOCKET) req->u.connect.pipeHandle,
SOL_SOCKET,
SO_UPDATE_CONNECT_CONTEXT,
NULL,
0);
if (req->u.connect.pipeHandle) {
/* If it is unix domain handle, the event comes from ConnectEx IOCP. */
setsockopt((SOCKET) req->u.connect.pipeHandle,
SOL_SOCKET,
SO_UPDATE_CONNECT_CONTEXT,
NULL,
0);
}
}
UNREGISTER_HANDLE_REQ(loop, handle);

View File

@ -214,6 +214,9 @@ TEST_DECLARE (pipe_getsockname_blocking)
TEST_DECLARE (pipe_pending_instances)
TEST_DECLARE (pipe_sendmsg)
TEST_DECLARE (pipe_server_close)
#ifdef _WIN32
TEST_DECLARE (pipe_win_uds)
#endif
TEST_DECLARE (connection_fail)
TEST_DECLARE (connection_fail_doesnt_auto_close)
TEST_DECLARE (shutdown_close_tcp)
@ -628,6 +631,10 @@ TASK_LIST_START
#endif
/* Seems to be either about 0.5s or 5s, depending on the OS. */
TEST_ENTRY_CUSTOM (pipe_set_non_blocking, 0, 0, 20000)
#ifdef _WIN32
TEST_ENTRY (pipe_win_uds)
#endif
TEST_ENTRY (pipe_set_chmod)
TEST_ENTRY (tty)
#ifdef _WIN32

View File

@ -24,7 +24,49 @@
#ifdef _WIN32
static int close_cb_called = 0;
static int connect_cb_called = 0;
static void close_cb(uv_handle_t *handle) {
ASSERT_NOT_NULL(handle);
close_cb_called++;
}
static void connect_cb_file(uv_connect_t *connect_req, int status) {
ASSERT_EQ(status, 0);
uv_close((uv_handle_t *) connect_req->handle, close_cb);
connect_cb_called++;
}
TEST_IMPL(pipe_win_uds) {
size_t size = MAX_PATH;
char path[MAX_PATH];
ASSERT_OK(uv_os_tmpdir(path, &size));
strcat_s(path, MAX_PATH, "\\uv_pipe_win_uds");
uv_fs_t fs;
uv_fs_unlink(uv_default_loop(), &fs, path, NULL);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
uv_pipe_t server;
uv_pipe_t client;
uv_connect_t req;
int r;
r = uv_pipe_init_ex(uv_default_loop(), &server, UV_PIPE_INIT_WIN_UDS);
ASSERT_OK(r);
r = uv_pipe_bind(&server, path);
ASSERT_OK(r);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
r = uv_pipe_init_ex(uv_default_loop(), &client, UV_PIPE_INIT_WIN_UDS);
ASSERT_OK(r);
uv_pipe_connect(&req, &client, path, connect_cb_file);
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT_EQ(1, close_cb_called);
ASSERT_EQ(1, connect_cb_called);
MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0;
}