src: format

This commit is contained in:
reito 2025-02-04 16:16:41 +08:00
parent 4a6741c53d
commit b3346a4296
4 changed files with 27 additions and 20 deletions

View File

@ -1388,6 +1388,7 @@ void uv__pipe_read_stop(uv_pipe_t* handle) {
void uv__pipe_close(uv_loop_t* loop, uv_pipe_t* handle) {
int i;
HANDLE pipeHandle;
struct linger uds_linger = {1, 0};
if (handle->flags & UV_HANDLE_READING) {
handle->flags &= ~UV_HANDLE_READING;
@ -1412,12 +1413,11 @@ void uv__pipe_close(uv_loop_t* loop, uv_pipe_t* handle) {
if (handle->flags & UV_HANDLE_WIN_UDS_PIPE) {
/* Force the subsequent closesocket to be abortative. */
struct linger l = {1, 0};
setsockopt((SOCKET)handle->handle,
SOL_SOCKET,
SO_LINGER,
(const char*)&l,
sizeof(l));
(const char*)&uds_linger,
sizeof(uds_linger));
}
if (handle->flags & UV_HANDLE_PIPESERVER) {
@ -1448,16 +1448,21 @@ void uv__pipe_close(uv_loop_t* loop, uv_pipe_t* handle) {
static void uv__pipe_queue_accept(uv_loop_t* loop, uv_pipe_t* handle,
uv_pipe_accept_t* req, BOOL firstInstance) {
int uds_err;
int wsa_err;
DWORD bytes_received;
CHAR accept_buf[2 * (sizeof(SOCKADDR_STORAGE) + 16)];
assert(handle->flags & UV_HANDLE_LISTENING);
if (!firstInstance) {
#if defined(UV__ENABLE_WIN_UDS_PIPE)
if (handle->flags & UV_HANDLE_WIN_UDS_PIPE) {
int uds_err = pipe_alloc_accept_unix_domain_socket(
loop, handle, req, handle->pathname, FALSE);
uds_err = pipe_alloc_accept_unix_domain_socket(
loop, handle, req, handle->pathname, FALSE);
if (uds_err) {
SET_REQ_ERROR(req, uds_err);
uv__insert_pending_req(loop, (uv_req_t*)req);
uv__insert_pending_req(loop, (uv_req_t *) req);
handle->reqs_pending++;
return;
}
@ -1481,9 +1486,6 @@ uds_pipe:
memset(&(req->u.io.overlapped), 0, sizeof(req->u.io.overlapped));
if (handle->flags & UV_HANDLE_WIN_UDS_PIPE) {
DWORD bytes_received;
CHAR accept_buf[2 * (sizeof(SOCKADDR_STORAGE) + 16)];
if (!uv_wsa_acceptex((SOCKET)handle->handle,
(SOCKET)req->pipeHandle,
accept_buf,
@ -1492,7 +1494,7 @@ uds_pipe:
sizeof(SOCKADDR_STORAGE) + 16,
&bytes_received,
&req->u.io.overlapped)) {
int wsa_err = WSAGetLastError();
wsa_err = WSAGetLastError();
if (wsa_err != ERROR_IO_PENDING) {
closesocket((SOCKET) req->pipeHandle);
req->pipeHandle = INVALID_HANDLE_VALUE;
@ -1608,6 +1610,7 @@ int uv__pipe_accept(uv_pipe_t* server, uv_stream_t* client) {
int uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
uv_loop_t* loop = handle->loop;
int i;
int err;
if (handle->flags & UV_HANDLE_LISTENING) {
handle->stream.serv.connection_cb = cb;
@ -1630,7 +1633,7 @@ int uv__pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
}
if (handle->flags & UV_HANDLE_WIN_UDS_PIPE) {
int err = listen((SOCKET) handle->handle, backlog);
err = listen((SOCKET) handle->handle, backlog);
if (err) {
return err;
}

View File

@ -576,7 +576,7 @@ int uv__tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
return handle->delayed_error;
}
if (!uv_wsa_acceptex) {
if (uv_wsa_acceptex == NULL) {
return WSAEAFNOSUPPORT;
}
@ -797,7 +797,7 @@ static int uv__tcp_try_connect(uv_connect_t* req,
goto out;
}
if (!uv_wsa_connectex) {
if (uv_wsa_connectex == NULL) {
return WSAEAFNOSUPPORT;
}
@ -1607,7 +1607,7 @@ int uv_socketpair(int type, int protocol, uv_os_sock_t fds[2], int flags0, int f
goto wsaerror;
if (!SetHandleInformation((HANDLE) client1, HANDLE_FLAG_INHERIT, 0))
goto error;
if (!uv_wsa_acceptex) {
if (uv_wsa_acceptex == NULL) {
err = WSAEAFNOSUPPORT;
goto cleanup;
}

View File

@ -73,6 +73,9 @@ void uv__winsock_init(void) {
WSAPROTOCOL_INFOW protocol_info;
int opt_len;
const GUID wsaid_acceptex = WSAID_ACCEPTEX;
const GUID wsaid_connectex = WSAID_CONNECTEX;
/* Set implicit binding address used by connectEx */
if (uv_ip4_addr("0.0.0.0", 0, &uv_addr_ip4_any_)) {
abort();
@ -126,9 +129,6 @@ void uv__winsock_init(void) {
/* Try to get WSA function pointers */
dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (dummy != INVALID_SOCKET) {
const GUID wsaid_acceptex = WSAID_ACCEPTEX;
const GUID wsaid_connectex = WSAID_CONNECTEX;
if (!uv__get_extension_function(
dummy, wsaid_acceptex, (void**)&uv_wsa_acceptex) ||
!uv__get_extension_function(

View File

@ -63,13 +63,15 @@ static void after_write_cb(uv_write_t *req, int status) {
}
static void client_connect_cb(uv_connect_t *connect_req, int status) {
uv_buf_t bufs[1];
uv_write_t *req;
ASSERT_EQ(status, 0);
client_connect_cb_called++;
// Server connected, send test data.
uv_buf_t bufs[1];
bufs[0] = uv_buf_init(pipe_test_data, strlen(pipe_test_data));
uv_write_t *req = malloc(sizeof(*req));
req = malloc(sizeof(*req));
req->data = NULL;
uv_write(req, connect_req->handle, bufs, 1, after_write_cb);
}
@ -102,11 +104,13 @@ static void read_cb(uv_stream_t *stream,
}
static void server_connect_cb(uv_stream_t *handle, int status) {
uv_pipe_t *conn;
ASSERT_EQ(status, 0);
server_connect_cb_called++;
// Client accepted, start reading.
uv_pipe_t *conn = malloc(sizeof(uv_pipe_t));
conn = malloc(sizeof(uv_pipe_t));
ASSERT_OK(uv_pipe_init_ex(handle->loop, conn, UV_PIPE_INIT_WIN_UDS));
ASSERT_OK(uv_accept(handle, (uv_stream_t*) conn));
ASSERT_OK(uv_read_start((uv_stream_t*) conn, alloc_cb, read_cb));