libuv/test/test-ping-pong.c

440 lines
11 KiB
C
Raw Permalink Normal View History

/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
2011-04-19 02:26:32 +00:00
#include "task.h"
2011-04-04 23:43:17 +00:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h> /* strlen */
static int completed_pingers = 0;
#if defined(__CYGWIN__) || defined(__MSYS__) || defined(__MVS__)
#define NUM_PINGS 100 /* fewer pings to avoid timeout */
#else
2011-04-07 02:51:59 +00:00
#define NUM_PINGS 1000
#endif
2011-04-04 23:43:17 +00:00
2011-04-07 02:51:59 +00:00
static char PING[] = "PING\n";
static char PONG[] = "PONG\n";
2011-07-20 19:14:15 +00:00
static int pinger_on_connect_count;
typedef struct {
int vectored_writes;
unsigned pongs;
unsigned state;
2011-07-02 00:54:17 +00:00
union {
uv_tcp_t tcp;
uv_pipe_t pipe;
2011-09-14 04:50:32 +00:00
} stream;
uv_connect_t connect_req;
char* pong;
2011-04-07 02:51:59 +00:00
} pinger_t;
static void alloc_cb(uv_handle_t* handle, size_t size, uv_buf_t* buf) {
buf->base = malloc(size);
buf->len = size;
}
static void ponger_on_close(uv_handle_t* handle) {
if (handle->data)
free(handle->data);
else
free(handle);
}
static void pinger_on_close(uv_handle_t* handle) {
pinger_t* pinger = (pinger_t*) handle->data;
2011-03-31 22:09:06 +00:00
ASSERT_EQ(NUM_PINGS, pinger->pongs);
2011-04-07 02:51:59 +00:00
if (handle == (uv_handle_t*) &pinger->stream.tcp) {
free(pinger); /* also frees handle */
} else {
uv_close((uv_handle_t*) &pinger->stream.tcp, ponger_on_close);
free(handle);
}
2011-04-07 02:51:59 +00:00
completed_pingers++;
}
2011-04-07 02:51:59 +00:00
static void pinger_after_write(uv_write_t* req, int status) {
ASSERT_OK(status);
free(req->data);
2011-04-07 02:51:59 +00:00
free(req);
}
2011-04-16 21:04:45 +00:00
static void pinger_write_ping(pinger_t* pinger) {
uv_stream_t* stream;
uv_write_t* req;
uv_buf_t bufs[sizeof PING - 1];
int i, nbufs;
stream = (uv_stream_t*) &pinger->stream.tcp;
if (!pinger->vectored_writes) {
/* Write a single buffer. */
nbufs = 1;
bufs[0] = uv_buf_init(PING, sizeof PING - 1);
} else {
/* Write multiple buffers, each with one byte in them. */
nbufs = sizeof PING - 1;
for (i = 0; i < nbufs; i++) {
bufs[i] = uv_buf_init(&PING[i], 1);
}
}
req = malloc(sizeof(*req));
ASSERT_NOT_NULL(req);
req->data = NULL;
ASSERT_OK(uv_write(req, stream, bufs, nbufs, pinger_after_write));
2011-04-16 21:04:45 +00:00
puts("PING");
2011-04-07 02:51:59 +00:00
}
2011-04-16 21:04:45 +00:00
static void pinger_read_cb(uv_stream_t* stream,
ssize_t nread,
const uv_buf_t* buf) {
2011-08-17 11:23:18 +00:00
ssize_t i;
2011-04-07 02:51:59 +00:00
pinger_t* pinger;
pinger = (pinger_t*) stream->data;
2011-05-03 00:35:11 +00:00
if (nread < 0) {
ASSERT_EQ(nread, UV_EOF);
2011-04-16 21:04:45 +00:00
puts("got EOF");
free(buf->base);
2011-05-03 00:35:11 +00:00
uv_close((uv_handle_t*) stream, pinger_on_close);
2011-05-03 00:35:11 +00:00
return;
}
/* Now we count the pongs */
for (i = 0; i < nread; i++) {
ASSERT_EQ(buf->base[i], pinger->pong[pinger->state]);
pinger->state = (pinger->state + 1) % strlen(pinger->pong);
2012-09-30 21:35:22 +00:00
if (pinger->state != 0)
continue;
printf("PONG %d\n", pinger->pongs);
pinger->pongs++;
if (pinger->pongs < NUM_PINGS) {
pinger_write_ping(pinger);
} else {
uv_close((uv_handle_t*) stream, pinger_on_close);
2012-09-30 21:35:22 +00:00
break;
}
}
2012-09-30 21:35:22 +00:00
free(buf->base);
}
static void ponger_read_cb(uv_stream_t* stream,
ssize_t nread,
const uv_buf_t* buf) {
uv_buf_t writebuf;
uv_write_t* req;
int i;
if (nread < 0) {
ASSERT_EQ(nread, UV_EOF);
puts("got EOF");
free(buf->base);
uv_close((uv_handle_t*) stream, ponger_on_close);
return;
}
/* Echo back */
for (i = 0; i < nread; i++) {
if (buf->base[i] == 'I')
buf->base[i] = 'O';
}
writebuf = uv_buf_init(buf->base, nread);
req = malloc(sizeof(*req));
ASSERT_NOT_NULL(req);
req->data = buf->base;
ASSERT_OK(uv_write(req, stream, &writebuf, 1, pinger_after_write));
}
static void pinger_on_connect(uv_connect_t* req, int status) {
pinger_t* pinger = (pinger_t*) req->handle->data;
2011-07-20 19:14:15 +00:00
pinger_on_connect_count++;
ASSERT_OK(status);
2011-04-04 23:43:17 +00:00
ASSERT_EQ(1, uv_is_readable(req->handle));
ASSERT_EQ(1, uv_is_writable(req->handle));
ASSERT_OK(uv_is_closing((uv_handle_t *) req->handle));
2012-02-08 20:01:33 +00:00
2011-04-07 02:51:59 +00:00
pinger_write_ping(pinger);
ASSERT_OK(uv_read_start((uv_stream_t*) req->handle,
alloc_cb,
pinger_read_cb));
2011-04-07 02:51:59 +00:00
}
2011-07-02 00:54:17 +00:00
/* same ping-pong test, but using IPv6 connection */
static void tcp_pinger_v6_new(int vectored_writes) {
2011-04-16 21:04:45 +00:00
int r;
struct sockaddr_in6 server_addr;
pinger_t* pinger;
ASSERT_OK(uv_ip6_addr("::1", TEST_PORT, &server_addr));
pinger = malloc(sizeof(*pinger));
ASSERT_NOT_NULL(pinger);
pinger->vectored_writes = vectored_writes;
2011-04-07 02:51:59 +00:00
pinger->state = 0;
pinger->pongs = 0;
pinger->pong = PING;
2011-11-30 04:26:52 +00:00
/* Try to connect to the server and do NUM_PINGS ping-pongs. */
2011-09-14 04:50:32 +00:00
r = uv_tcp_init(uv_default_loop(), &pinger->stream.tcp);
pinger->stream.tcp.data = pinger;
ASSERT_OK(r);
2011-04-07 02:51:59 +00:00
/* We are never doing multiple reads/connects at a time anyway, so these
* handles can be pre-initialized. */
r = uv_tcp_connect(&pinger->connect_req,
&pinger->stream.tcp,
(const struct sockaddr*) &server_addr,
pinger_on_connect);
ASSERT_OK(r);
2011-07-20 19:14:15 +00:00
/* Synchronous connect callbacks are not allowed. */
ASSERT_OK(pinger_on_connect_count);
}
static void tcp_pinger_new(int vectored_writes) {
2011-07-02 00:54:17 +00:00
int r;
struct sockaddr_in server_addr;
pinger_t* pinger;
ASSERT_OK(uv_ip4_addr("127.0.0.1", TEST_PORT, &server_addr));
pinger = malloc(sizeof(*pinger));
ASSERT_NOT_NULL(pinger);
pinger->vectored_writes = vectored_writes;
2011-07-02 00:54:17 +00:00
pinger->state = 0;
pinger->pongs = 0;
pinger->pong = PING;
2011-11-30 04:26:52 +00:00
/* Try to connect to the server and do NUM_PINGS ping-pongs. */
2011-09-14 04:50:32 +00:00
r = uv_tcp_init(uv_default_loop(), &pinger->stream.tcp);
pinger->stream.tcp.data = pinger;
ASSERT_OK(r);
/* We are never doing multiple reads/connects at a time anyway, so these
* handles can be pre-initialized. */
r = uv_tcp_connect(&pinger->connect_req,
&pinger->stream.tcp,
(const struct sockaddr*) &server_addr,
pinger_on_connect);
ASSERT_OK(r);
2011-07-20 19:14:15 +00:00
/* Synchronous connect callbacks are not allowed. */
ASSERT_OK(pinger_on_connect_count);
}
2011-07-02 00:04:05 +00:00
static void pipe_pinger_new(int vectored_writes) {
2011-07-02 00:04:05 +00:00
int r;
pinger_t* pinger;
2011-07-02 00:04:05 +00:00
pinger = malloc(sizeof(*pinger));
ASSERT_NOT_NULL(pinger);
pinger->vectored_writes = vectored_writes;
2011-07-02 00:04:05 +00:00
pinger->state = 0;
pinger->pongs = 0;
pinger->pong = PING;
2011-07-02 00:04:05 +00:00
2011-11-30 04:26:52 +00:00
/* Try to connect to the server and do NUM_PINGS ping-pongs. */
r = uv_pipe_init(uv_default_loop(), &pinger->stream.pipe, 0);
2011-09-14 04:50:32 +00:00
pinger->stream.pipe.data = pinger;
ASSERT_OK(r);
2011-07-02 00:04:05 +00:00
/* We are never doing multiple reads/connects at a time anyway, so these
* handles can be pre-initialized. */
2011-11-04 23:06:53 +00:00
uv_pipe_connect(&pinger->connect_req, &pinger->stream.pipe, TEST_PIPENAME,
2011-07-20 19:14:15 +00:00
pinger_on_connect);
/* Synchronous connect callbacks are not allowed. */
ASSERT_OK(pinger_on_connect_count);
2011-07-02 00:04:05 +00:00
}
static void socketpair_pinger_new(int vectored_writes) {
pinger_t* pinger;
uv_os_sock_t fds[2];
uv_tcp_t* ponger;
pinger = malloc(sizeof(*pinger));
ASSERT_NOT_NULL(pinger);
pinger->vectored_writes = vectored_writes;
pinger->state = 0;
pinger->pongs = 0;
pinger->pong = PONG;
/* Try to make a socketpair and do NUM_PINGS ping-pongs. */
(void)uv_default_loop(); /* ensure WSAStartup has been performed */
ASSERT_OK(uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE));
#ifndef _WIN32
/* On Windows, this is actually a UV_TCP, but libuv doesn't detect that. */
2021.07.21, Version 1.42.0 (Stable) Changes since version 1.41.0: * doc: fix code highlighting (Darshan Sen) * test: move to ASSERT_NULL and ASSERT_NOT_NULL test macros (tjarlama) * zos: build in ascii code page (Shuowang (Wayne) Zhang) * zos: don't use nanosecond timestamp fields (Shuowang (Wayne) Zhang) * zos: introduce zoslib (Shuowang (Wayne) Zhang) * zos: use strnlen() from zoslib (Shuowang (Wayne) Zhang) * zos: use nanosleep() from zoslib (Shuowang (Wayne) Zhang) * zos: use __getargv() from zoslib to get exe path (Shuowang (Wayne) Zhang) * zos: treat __rfim_utok as binary (Shuowang (Wayne) Zhang) * zos: use execvpe() to set environ explictly (Shuowang (Wayne) Zhang) * zos: use custom proctitle implementation (Shuowang (Wayne) Zhang) * doc: add instructions for building on z/OS (Shuowang (Wayne) Zhang) * linux,udp: enable full ICMP error reporting (Ondřej Surý) * test: fix test-udp-send-unreachable (Ondřej Surý) * include: fix typo in documentation (Tobias Nießen) * chore: use for(;;) instead of while (Yash Ladha) * test: remove string + int warning on udp-pummel (Juan José Arboleda) * cmake: fix linker flags (Zhao Zhili) * test: fix stack-use-after-scope (Zhao Zhili) * unix: expose thread_stack_size() internally (Brandon Cheng) * darwin: use RLIMIT_STACK for fsevents pthread (Brandon Cheng) * darwin: abort on pthread_attr_init fail (Brandon Cheng) * benchmark: remove unreachable code (Matvii Hodovaniuk) * macos: fix memleaks in uv__get_cpu_speed (George Zhao) * Make Thread Sanitizer aware of file descriptor close in uv__close() (Ondřej Surý) * darwin: fix iOS compilation and functionality (Hayden) * linux: work around copy_file_range() cephfs bug (Ben Noordhuis) * zos: implement uv_get_constrained_memory() (Shuowang (Wayne) Zhang) * zos: fix uv_get_free_memory() (Shuowang (Wayne) Zhang) * zos: use CVTRLSTG to get total memory accurately (Shuowang (Wayne) Zhang) * ibmi: Handle interface names longer than 10 chars (Kevin Adler) * docs: update read-the-docs version of sphinx (Jameson Nash) * unix: refactor uv_try_write (twosee) * linux-core: add proper divide by zero assert (yiyuaner) * misc: remove unnecessary _GNU_SOURCE macros (Darshan Sen) * test: log to stdout to conform TAP spec (bbara) * win,fs: fix C4090 warning with MSVC (SeverinLeonhardt) * build: some systems provide dlopen() in libc (Andy Fiddaman) * include: add EOVERFLOW status code mapping (Darshan Sen) * unix,fs: use uv__load_relaxed and uv__store_relaxed (Darshan Sen) * win: fix string encoding issue of uv_os_gethostname (Eagle Liang) * unix,process: add uv__write_errno helper function (Ricky Zhou) * Re-merge "unix,stream: clear read/write states on close/eof" (Jameson Nash) * unix,core: fix errno handling in uv__getpwuid_r (Darshan Sen) * errors: map ESOCKTNOSUPPORT errno (Ryan Liptak) * doc: uv_read_stop always succeeds (Simon Kissane) * inet: fix inconsistent return value of inet_ntop6 (twosee) * darwin: fix -Wsometimes-uninitialized warning (twosee) * stream: introduce uv_try_write2 function (twosee) * poll,win: UV_PRIORITIZED option should not assert (twosee) * src: DragonFlyBSD has mmsghdr struct too (David Carlier) * cleanup,win: Remove _WIN32 guards on threadpool (James M Snell) * freebsd: fix an incompatible pointer type warning (Darshan Sen) * core: Correct the conditionals for {cloexec,nonblock}_ioctl (Ali Mohammad Pur) * win,tcp: make uv_close work more like unix (Jameson Nash) * doc: more accurate list of valid send_handle's (twosee) * win,tcp: translate system errors correctly (twosee) * unix: implement cpu_relax() on ppc64 (Ben Noordhuis) * docs: move list of project links under PR control (Jameson Nash) * test: wrong pointer arithmetic multiplier (Erkhes N) * doc: switch discussion forum to github (Jameson Nash) * idna: fix OOB read in punycode decoder (Ben Noordhuis) * build: make sure -fvisibility=hidden is set (Santiago Gimeno) * illumos: event ports to epoll (tjarlama) * illumos,tty: UV_TTY_MODE_IO waits for 4 bytes (Joshua M. Clulow) * doc: add vtjnash GPG ID (Jameson Nash) * linux: read CPU model information on ppc (Richard Lau) * darwin: fix uv_barrier race condition (Guilherme Íscaro) * unix,stream: fix loop hang after uv_shutdown (Jameson Nash) * doc,udp: note that suggested_size is 1 max-sized dgram (Ryan Liptak) * mingw: fix building for ARM/AArch64 (Martin Storsjö) * unix: strnlen is not available on Solaris 10 (Claes Nästén) * sunos: restore use of event ports (Andy Fiddaman) * sunos,cmake: use thread-safe errno (Andy Fiddaman) -----BEGIN PGP SIGNATURE----- iQJGBAABCAAwFiEErq0KS2hnZ3UaDkrvNKJfsSgkZRQFAmD2OHUSHHZ0am5hc2hA Z21haWwuY29tAAoJEDSiX7EoJGUU6XsQAJqkq5qV54EEFQAIf/AV9e4pt5uua2iF bTyExNGyty5TW4OCytSxakLWS/9lN5vQo6/bjeUEfhq8a1BmLzJq5Nnmc8ntlYM6 n89vZSRjgLNwQ2WuRV9akCMTPYydeJc6RboEjTDVlWtSr4QDCwK+fKgaMil+9uow Y8biEme/vIcpJNOE3IdhivUoS1Hl1PJrVbhJapHBQ6j4xf8CIrFBwn9qF0IX+Ngp 9xZVvJFXQkZzqLqkHeMasGCp+hmQDnAiXKO3vbUJbeVwoCukDYmVG8Pb3H3RIyo9 yZkdBpOZ1GEmnPY766IkArThM+/WBWTgz6pTOl59Zx0Wa5Dmr8ASUiauE/EEARS4 v/QUQA13MS8cgOBhmPjrLQ9Kv6HPvLuZSjshEJz4RdL8aSThoQ7Om+AlR679wnyK vlcfNLoh+Jw1zCWKWO6c5BiqcB/8J/JPT2N0vMmT6+RZ8AiqyjGpBw+t1HeBkdW5 CPJX06CXk7vsvCKbw4w8i8Xl40zm9yws5tO7ukG/lkmB5EUKhMe1z/5pTAWoFJV/ srs6S+g3xmJ1oBeytjjEra/iJji/6jQ/oLbYeA+mvBxV5+hu7Mtnpzl0vWKrN5M2 ewxOvJJtggT1V2WcVqYLmHdZpug+pspG6Uwm6/TG/379IFot3O4OjPZ8wlrLgaNt PU0FlUDCxyvT =gkXG -----END PGP SIGNATURE----- Merge tag 'v1.42.0' into merge_1.42.0 PR-URL: https://github.com/libuv/libuv/pull/3245 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-07-20 16:24:19 +00:00
ASSERT_EQ(uv_guess_handle((uv_os_fd_t) fds[0]), UV_NAMED_PIPE);
ASSERT_EQ(uv_guess_handle((uv_os_fd_t) fds[1]), UV_NAMED_PIPE);
#endif
ASSERT_OK(uv_tcp_init(uv_default_loop(), &pinger->stream.tcp));
pinger->stream.pipe.data = pinger;
ASSERT_OK(uv_tcp_open(&pinger->stream.tcp, fds[1]));
ponger = malloc(sizeof(*ponger));
ASSERT_NOT_NULL(ponger);
ponger->data = NULL;
ASSERT_OK(uv_tcp_init(uv_default_loop(), ponger));
ASSERT_OK(uv_tcp_open(ponger, fds[0]));
pinger_write_ping(pinger);
ASSERT_OK(uv_read_start((uv_stream_t*) &pinger->stream.tcp,
alloc_cb,
pinger_read_cb));
ASSERT_OK(uv_read_start((uv_stream_t*) ponger,
alloc_cb,
ponger_read_cb));
2011-07-02 00:04:05 +00:00
}
static void pipe2_pinger_new(int vectored_writes) {
2021.07.21, Version 1.42.0 (Stable) Changes since version 1.41.0: * doc: fix code highlighting (Darshan Sen) * test: move to ASSERT_NULL and ASSERT_NOT_NULL test macros (tjarlama) * zos: build in ascii code page (Shuowang (Wayne) Zhang) * zos: don't use nanosecond timestamp fields (Shuowang (Wayne) Zhang) * zos: introduce zoslib (Shuowang (Wayne) Zhang) * zos: use strnlen() from zoslib (Shuowang (Wayne) Zhang) * zos: use nanosleep() from zoslib (Shuowang (Wayne) Zhang) * zos: use __getargv() from zoslib to get exe path (Shuowang (Wayne) Zhang) * zos: treat __rfim_utok as binary (Shuowang (Wayne) Zhang) * zos: use execvpe() to set environ explictly (Shuowang (Wayne) Zhang) * zos: use custom proctitle implementation (Shuowang (Wayne) Zhang) * doc: add instructions for building on z/OS (Shuowang (Wayne) Zhang) * linux,udp: enable full ICMP error reporting (Ondřej Surý) * test: fix test-udp-send-unreachable (Ondřej Surý) * include: fix typo in documentation (Tobias Nießen) * chore: use for(;;) instead of while (Yash Ladha) * test: remove string + int warning on udp-pummel (Juan José Arboleda) * cmake: fix linker flags (Zhao Zhili) * test: fix stack-use-after-scope (Zhao Zhili) * unix: expose thread_stack_size() internally (Brandon Cheng) * darwin: use RLIMIT_STACK for fsevents pthread (Brandon Cheng) * darwin: abort on pthread_attr_init fail (Brandon Cheng) * benchmark: remove unreachable code (Matvii Hodovaniuk) * macos: fix memleaks in uv__get_cpu_speed (George Zhao) * Make Thread Sanitizer aware of file descriptor close in uv__close() (Ondřej Surý) * darwin: fix iOS compilation and functionality (Hayden) * linux: work around copy_file_range() cephfs bug (Ben Noordhuis) * zos: implement uv_get_constrained_memory() (Shuowang (Wayne) Zhang) * zos: fix uv_get_free_memory() (Shuowang (Wayne) Zhang) * zos: use CVTRLSTG to get total memory accurately (Shuowang (Wayne) Zhang) * ibmi: Handle interface names longer than 10 chars (Kevin Adler) * docs: update read-the-docs version of sphinx (Jameson Nash) * unix: refactor uv_try_write (twosee) * linux-core: add proper divide by zero assert (yiyuaner) * misc: remove unnecessary _GNU_SOURCE macros (Darshan Sen) * test: log to stdout to conform TAP spec (bbara) * win,fs: fix C4090 warning with MSVC (SeverinLeonhardt) * build: some systems provide dlopen() in libc (Andy Fiddaman) * include: add EOVERFLOW status code mapping (Darshan Sen) * unix,fs: use uv__load_relaxed and uv__store_relaxed (Darshan Sen) * win: fix string encoding issue of uv_os_gethostname (Eagle Liang) * unix,process: add uv__write_errno helper function (Ricky Zhou) * Re-merge "unix,stream: clear read/write states on close/eof" (Jameson Nash) * unix,core: fix errno handling in uv__getpwuid_r (Darshan Sen) * errors: map ESOCKTNOSUPPORT errno (Ryan Liptak) * doc: uv_read_stop always succeeds (Simon Kissane) * inet: fix inconsistent return value of inet_ntop6 (twosee) * darwin: fix -Wsometimes-uninitialized warning (twosee) * stream: introduce uv_try_write2 function (twosee) * poll,win: UV_PRIORITIZED option should not assert (twosee) * src: DragonFlyBSD has mmsghdr struct too (David Carlier) * cleanup,win: Remove _WIN32 guards on threadpool (James M Snell) * freebsd: fix an incompatible pointer type warning (Darshan Sen) * core: Correct the conditionals for {cloexec,nonblock}_ioctl (Ali Mohammad Pur) * win,tcp: make uv_close work more like unix (Jameson Nash) * doc: more accurate list of valid send_handle's (twosee) * win,tcp: translate system errors correctly (twosee) * unix: implement cpu_relax() on ppc64 (Ben Noordhuis) * docs: move list of project links under PR control (Jameson Nash) * test: wrong pointer arithmetic multiplier (Erkhes N) * doc: switch discussion forum to github (Jameson Nash) * idna: fix OOB read in punycode decoder (Ben Noordhuis) * build: make sure -fvisibility=hidden is set (Santiago Gimeno) * illumos: event ports to epoll (tjarlama) * illumos,tty: UV_TTY_MODE_IO waits for 4 bytes (Joshua M. Clulow) * doc: add vtjnash GPG ID (Jameson Nash) * linux: read CPU model information on ppc (Richard Lau) * darwin: fix uv_barrier race condition (Guilherme Íscaro) * unix,stream: fix loop hang after uv_shutdown (Jameson Nash) * doc,udp: note that suggested_size is 1 max-sized dgram (Ryan Liptak) * mingw: fix building for ARM/AArch64 (Martin Storsjö) * unix: strnlen is not available on Solaris 10 (Claes Nästén) * sunos: restore use of event ports (Andy Fiddaman) * sunos,cmake: use thread-safe errno (Andy Fiddaman) -----BEGIN PGP SIGNATURE----- iQJGBAABCAAwFiEErq0KS2hnZ3UaDkrvNKJfsSgkZRQFAmD2OHUSHHZ0am5hc2hA Z21haWwuY29tAAoJEDSiX7EoJGUU6XsQAJqkq5qV54EEFQAIf/AV9e4pt5uua2iF bTyExNGyty5TW4OCytSxakLWS/9lN5vQo6/bjeUEfhq8a1BmLzJq5Nnmc8ntlYM6 n89vZSRjgLNwQ2WuRV9akCMTPYydeJc6RboEjTDVlWtSr4QDCwK+fKgaMil+9uow Y8biEme/vIcpJNOE3IdhivUoS1Hl1PJrVbhJapHBQ6j4xf8CIrFBwn9qF0IX+Ngp 9xZVvJFXQkZzqLqkHeMasGCp+hmQDnAiXKO3vbUJbeVwoCukDYmVG8Pb3H3RIyo9 yZkdBpOZ1GEmnPY766IkArThM+/WBWTgz6pTOl59Zx0Wa5Dmr8ASUiauE/EEARS4 v/QUQA13MS8cgOBhmPjrLQ9Kv6HPvLuZSjshEJz4RdL8aSThoQ7Om+AlR679wnyK vlcfNLoh+Jw1zCWKWO6c5BiqcB/8J/JPT2N0vMmT6+RZ8AiqyjGpBw+t1HeBkdW5 CPJX06CXk7vsvCKbw4w8i8Xl40zm9yws5tO7ukG/lkmB5EUKhMe1z/5pTAWoFJV/ srs6S+g3xmJ1oBeytjjEra/iJji/6jQ/oLbYeA+mvBxV5+hu7Mtnpzl0vWKrN5M2 ewxOvJJtggT1V2WcVqYLmHdZpug+pspG6Uwm6/TG/379IFot3O4OjPZ8wlrLgaNt PU0FlUDCxyvT =gkXG -----END PGP SIGNATURE----- Merge tag 'v1.42.0' into merge_1.42.0 PR-URL: https://github.com/libuv/libuv/pull/3245 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
2021-07-20 16:24:19 +00:00
uv_os_fd_t fds[2];
pinger_t* pinger;
uv_pipe_t* ponger;
/* Try to make a pipe and do NUM_PINGS pings. */
ASSERT_OK(uv_pipe(fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE));
ASSERT_EQ(uv_guess_handle(fds[0]), UV_NAMED_PIPE);
ASSERT_EQ(uv_guess_handle(fds[1]), UV_NAMED_PIPE);
ponger = malloc(sizeof(*ponger));
ASSERT_NOT_NULL(ponger);
ASSERT_OK(uv_pipe_init(uv_default_loop(), ponger, 0));
ASSERT_OK(uv_pipe_open(ponger, fds[0]));
pinger = malloc(sizeof(*pinger));
ASSERT_NOT_NULL(pinger);
pinger->vectored_writes = vectored_writes;
pinger->state = 0;
pinger->pongs = 0;
pinger->pong = PING;
ASSERT_OK(uv_pipe_init(uv_default_loop(), &pinger->stream.pipe, 0));
ASSERT_OK(uv_pipe_open(&pinger->stream.pipe, fds[1]));
pinger->stream.pipe.data = pinger; /* record for close_cb */
ponger->data = pinger; /* record for read_cb */
pinger_write_ping(pinger);
ASSERT_OK(uv_read_start((uv_stream_t*) ponger, alloc_cb, pinger_read_cb));
}
static int run_ping_pong_test(void) {
uv_run(uv_default_loop(), UV_RUN_DEFAULT);
ASSERT_EQ(1, completed_pingers);
2011-07-02 00:54:17 +00:00
MAKE_VALGRIND_HAPPY(uv_default_loop());
2011-07-02 00:54:17 +00:00
return 0;
}
TEST_IMPL(tcp_ping_pong) {
tcp_pinger_new(0);
run_ping_pong_test();
completed_pingers = 0;
socketpair_pinger_new(0);
return run_ping_pong_test();
}
TEST_IMPL(tcp_ping_pong_vec) {
tcp_pinger_new(1);
run_ping_pong_test();
completed_pingers = 0;
socketpair_pinger_new(1);
return run_ping_pong_test();
}
TEST_IMPL(tcp6_ping_pong) {
if (!can_ipv6())
RETURN_SKIP("IPv6 not supported");
tcp_pinger_v6_new(0);
return run_ping_pong_test();
}
2011-07-02 00:54:17 +00:00
TEST_IMPL(tcp6_ping_pong_vec) {
if (!can_ipv6())
RETURN_SKIP("IPv6 not supported");
tcp_pinger_v6_new(1);
return run_ping_pong_test();
2011-07-02 00:54:17 +00:00
}
TEST_IMPL(pipe_ping_pong) {
pipe_pinger_new(0);
run_ping_pong_test();
completed_pingers = 0;
pipe2_pinger_new(0);
return run_ping_pong_test();
}
2011-07-02 00:04:05 +00:00
TEST_IMPL(pipe_ping_pong_vec) {
pipe_pinger_new(1);
run_ping_pong_test();
completed_pingers = 0;
pipe2_pinger_new(1);
return run_ping_pong_test();
2011-07-02 00:04:05 +00:00
}