test-watcher-cross-stop.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 #include "uv.h"
23 #include "task.h"
24 
25 #include <string.h>
26 #include <errno.h>
27 
28 /* NOTE: Number should be big enough to trigger this problem */
29 #if defined(__CYGWIN__) || defined(__MSYS__) || defined(__PASE__)
30 /* Cygwin crashes or hangs in socket() with too many AF_INET sockets. */
31 /* IBMi PASE timeout with too many AF_INET sockets. */
32 static uv_udp_t sockets[1250];
33 #else
34 static uv_udp_t sockets[2500];
35 #endif
37 static char slab[1];
38 static unsigned int recv_cb_called;
39 static unsigned int send_cb_called;
40 static unsigned int close_cb_called;
41 
42 static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
43  buf->base = slab;
44  buf->len = sizeof(slab);
45 }
46 
47 
48 static void recv_cb(uv_udp_t* handle,
49  ssize_t nread,
50  const uv_buf_t* buf,
51  const struct sockaddr* addr,
52  unsigned flags) {
54 }
55 
56 
57 static void send_cb(uv_udp_send_t* req, int status) {
59 }
60 
61 
62 static void close_cb(uv_handle_t* handle) {
64 }
65 
66 
67 TEST_IMPL(watcher_cross_stop) {
68 #if defined(__MVS__)
69  RETURN_SKIP("zOS does not allow address or port reuse when using UDP sockets");
70 #endif
72  unsigned int i;
73  struct sockaddr_in addr;
74  uv_buf_t buf;
75  char big_string[1024];
76 
78 
79  ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
80  memset(big_string, 'A', sizeof(big_string));
81  buf = uv_buf_init(big_string, sizeof(big_string));
82 
83  for (i = 0; i < ARRAY_SIZE(sockets); i++) {
84  ASSERT(0 == uv_udp_init(loop, &sockets[i]));
85  ASSERT(0 == uv_udp_bind(&sockets[i],
86  (const struct sockaddr*) &addr,
89  ASSERT(0 == uv_udp_send(&reqs[i],
90  &sockets[i],
91  &buf,
92  1,
93  (const struct sockaddr*) &addr,
94  send_cb));
95  }
96 
97  while (recv_cb_called == 0)
99 
100  for (i = 0; i < ARRAY_SIZE(sockets); i++)
102 
103  ASSERT(recv_cb_called > 0);
104 
106 
109 
111  return 0;
112 }
async_greeter_server_with_graceful_shutdown.loop
loop
Definition: async_greeter_server_with_graceful_shutdown.py:59
slab
static char slab[1]
Definition: test-watcher-cross-stop.c:37
reqs
static uv_udp_send_t reqs[ARRAY_SIZE(sockets)]
Definition: test-watcher-cross-stop.c:36
ARRAY_SIZE
#define ARRAY_SIZE(array)
Definition: bloaty.cc:101
task.h
memset
return memset(p, 0, total)
string.h
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
uv_udp_send
UV_EXTERN int uv_udp_send(uv_udp_send_t *req, uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr, uv_udp_send_cb send_cb)
Definition: uv-common.c:408
ASSERT
#define ASSERT(expr)
Definition: task.h:102
recv_cb
static void recv_cb(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags)
Definition: test-watcher-cross-stop.c:48
close_cb
static void close_cb(uv_handle_t *handle)
Definition: test-watcher-cross-stop.c:62
status
absl::Status status
Definition: rls.cc:251
recv_cb_called
static unsigned int recv_cb_called
Definition: test-watcher-cross-stop.c:38
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
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_ip4_addr
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
Definition: uv-common.c:221
uv_udp_init
UV_EXTERN int uv_udp_init(uv_loop_t *, uv_udp_t *handle)
Definition: unix/udp.c:988
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
ssize_t
intptr_t ssize_t
Definition: win.h:27
send_cb_called
static unsigned int send_cb_called
Definition: test-watcher-cross-stop.c:39
req
static uv_connect_t req
Definition: test-connection-fail.c:30
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
uv_udp_s
Definition: uv.h:629
TEST_IMPL
TEST_IMPL(watcher_cross_stop)
Definition: test-watcher-cross-stop.c:67
uv_udp_send_s
Definition: uv.h:645
uv.h
uv_udp_recv_start
UV_EXTERN int uv_udp_recv_start(uv_udp_t *handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
Definition: uv-common.c:438
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
TEST_FILE_LIMIT
#define TEST_FILE_LIMIT(num)
Definition: task.h:271
uv_buf_t
Definition: unix.h:121
uv_udp_bind
UV_EXTERN int uv_udp_bind(uv_udp_t *handle, const struct sockaddr *addr, unsigned int flags)
Definition: uv-common.c:296
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
UV_UDP_REUSEADDR
@ UV_UDP_REUSEADDR
Definition: uv.h:608
alloc_cb
static void alloc_cb(uv_handle_t *handle, size_t size, uv_buf_t *buf)
Definition: test-watcher-cross-stop.c:42
UV_RUN_ONCE
@ UV_RUN_ONCE
Definition: uv.h:255
uv_buf_init
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
sockets
static uv_udp_t sockets[2500]
Definition: test-watcher-cross-stop.c:34
RETURN_SKIP
#define RETURN_SKIP(explanation)
Definition: task.h:262
handle
static csh handle
Definition: test_arm_regression.c:16
close_cb_called
static unsigned int close_cb_called
Definition: test-watcher-cross-stop.c:40
uv_handle_s
Definition: uv.h:441
uv_loop_s
Definition: uv.h:1767
size
voidpf void uLong size
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
addr
struct sockaddr_in addr
Definition: libuv/docs/code/tcp-echo-server/main.c:10
errno.h
send_cb
static void send_cb(uv_udp_send_t *req, int status)
Definition: test-watcher-cross-stop.c:57
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


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