test-poll-closesocket.c
Go to the documentation of this file.
1 /* Copyright Joyent, Inc. and other Node contributors. 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 
23 #include <errno.h>
24 
25 #include "uv.h"
26 #include "task.h"
27 
28 #ifdef _WIN32
29 static uv_os_sock_t sock;
30 static uv_poll_t handle;
31 static int close_cb_called = 0;
32 
33 
34 static void close_cb(uv_handle_t* h) {
36 }
37 
38 
39 static void poll_cb(uv_poll_t* h, int status, int events) {
40  int r;
41 
42  ASSERT(status == 0);
43  ASSERT(h == &handle);
44 
46  ASSERT(r == 0);
47 
48  closesocket(sock);
50 
51 }
52 #endif
53 
54 
55 TEST_IMPL(poll_closesocket) {
56 #ifndef _WIN32
57  RETURN_SKIP("Test only relevant on Windows");
58 #else
59  struct WSAData wsa_data;
60  int r;
61  unsigned long on;
62  struct sockaddr_in addr;
63 
64  r = WSAStartup(MAKEWORD(2, 2), &wsa_data);
65  ASSERT(r == 0);
66 
67  sock = socket(AF_INET, SOCK_STREAM, 0);
68  ASSERT(sock != INVALID_SOCKET);
69  on = 1;
70  r = ioctlsocket(sock, FIONBIO, &on);
71  ASSERT(r == 0);
72 
73  r = uv_ip4_addr("127.0.0.1", TEST_PORT, &addr);
74  ASSERT(r == 0);
75 
76  r = connect(sock, (const struct sockaddr*) &addr, sizeof addr);
77  ASSERT(r != 0);
78  ASSERT(WSAGetLastError() == WSAEWOULDBLOCK);
79 
81  ASSERT(r == 0);
83  ASSERT(r == 0);
84 
86 
87  ASSERT(close_cb_called == 1);
88 
90  return 0;
91 #endif
92 }
task.h
UV_WRITABLE
@ UV_WRITABLE
Definition: uv.h:791
uv_poll_init_socket
UV_EXTERN int uv_poll_init_socket(uv_loop_t *loop, uv_poll_t *handle, uv_os_sock_t socket)
Definition: unix/poll.c:96
ASSERT
#define ASSERT(expr)
Definition: task.h:102
status
absl::Status status
Definition: rls.cc:251
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
uv_poll_start
UV_EXTERN int uv_poll_start(uv_poll_t *handle, int events, uv_poll_cb cb)
Definition: unix/poll.c:118
TEST_PORT
#define TEST_PORT
Definition: task.h:53
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
uv_os_sock_t
int uv_os_sock_t
Definition: unix.h:127
uv_ip4_addr
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
Definition: uv-common.c:221
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
close_cb_called
static int close_cb_called
Definition: benchmark-million-timers.c:28
UV_READABLE
@ UV_READABLE
Definition: uv.h:790
close_cb
static void close_cb(uv_handle_t *handle)
Definition: benchmark-million-timers.c:36
poll_cb
static void poll_cb(uv_fs_t *req)
Definition: fs-poll.c:185
uv.h
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
uv_poll_s
Definition: uv.h:783
fix_build_deps.r
r
Definition: fix_build_deps.py:491
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
handle
static csh handle
Definition: test_arm_regression.c:16
TEST_IMPL
TEST_IMPL(poll_closesocket)
Definition: test-poll-closesocket.c:55
uv_handle_s
Definition: uv.h:441
test_server.socket
socket
Definition: test_server.py:65
closesocket
static int closesocket(int sock)
Definition: bio_test.cc:46
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
errno.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26