提交 f4c38e4c authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Update libuv to 1.35.0

上级 965ef7a4
......@@ -413,3 +413,8 @@ Carl Lei <xecycle@gmail.com>
Stefan Bender <stefan.bender@ntnu.no>
nia <nia@NetBSD.org>
virtualyw <virtualyw@gmail.com>
Witold Kręcicki <wpk@isc.org>
Dominique Dumont <dod@debian.org>
Manuel BACHMANN <tarnyko@tarnyko.net>
Marek Vavrusa <marek@vavrusa.com>
TK-one <tk5641@naver.com>
......@@ -48,11 +48,11 @@ the [Google C/C++ style guide]. Some of the key points, as well as some
additional guidelines, are enumerated below.
* Code that is specific to unix-y platforms should be placed in `src/unix`, and
declarations go into `include/uv-unix.h`.
declarations go into `include/uv/unix.h`.
* Source code that is Windows-specific goes into `src/win`, and related
publicly exported types, functions and macro declarations should generally
be declared in `include/uv-win.h`.
be declared in `include/uv/win.h`.
* Names should be descriptive and concise.
......
2020.01.24, Version 1.34.2 (Stable)
2020.03.12, Version 1.35.0 (Stable)
Changes since version 1.34.2:
* src: android build fix (David Carlier)
* build: make code compilable for iOS on Xcode (ssrlive)
* ibmi: skip unsupported fs test cases (Xu Meng)
* ibmi: ensure that pipe backlog is not zero (Xu Meng)
* test,udp6: fix udp_ipv6 test flakiness (Jameson Nash)
* test: fix fs_event_watch_dir_recursive flakiness (Santiago Gimeno)
* pipe: disallow listening on an IPC pipe (Witold Kręcicki)
* build,cmake: improve buil experience (Isabella Muerte)
* unix: remove support for FreeBSD < 10 (Saúl Ibarra Corretgé)
* linux: simplify uv__accept() (Ben Noordhuis)
* linux: assume presence of SOCK_CLOEXEC flag (Ben Noordhuis)
* linux: simplify uv__dup2_cloexec() (Ben Noordhuis)
* freebsd,linux: simplify uv__make_socketpair() (Ben Noordhuis)
* unix: fix error handling in uv__make_socketpair() (Ben Noordhuis)
* freebsd,linux: simplify uv__make_pipe() (Ben Noordhuis)
* unix: fix error handling in uv__make_pipe() (Ben Noordhuis)
* linux: simplify uv__async_eventfd() (Ben Noordhuis)
* linux: assume the presence of inotify system calls (Ben Noordhuis)
* doc: strip ICC profile from 2 jpg files (Dominique Dumont)
* unix: make uv_tcp_keepalive predictable (Manuel BACHMANN)
* docs: uv_setup_args() may take ownership of argv (Ben Noordhuis)
* unix: fix error path in uv_setup_args() (Ben Noordhuis)
* unix: fix size check in uv_get_process_title() (Ben Noordhuis)
* doc: add erw7 to maintainers (erw7)
* test: fixed udp4_echo_server implementation (Marek Vavrusa)
* test: added udp ping benchmark (1,10,100 pingers) (Marek Vavrusa)
* freebsd,linux: add recvmmsg() + sendmmsg() udp implementation (Marek Vavrusa)
* win,pipe: DRY/simplify some code paths (Jameson Nash)
* win: address some style nits (Jameson Nash)
* win,pipe: ensure `req->event_handle` is defined (Elliot Saba)
* win,pipe: consolidate overlapped initialization (Elliot Saba)
* win,pipe: erase event_handle after deleting pointer (Jameson Nash)
* build: fix android cmake build, build missing file (Ben Noordhuis)
* test: skip some UDP tests on IBMi (Xu Meng)
* test: skip some spawn test cases on IBMi (Xu Meng)
* src: fix wrong method name in comment (TK-one)
* test: add UV_TIMEOUT_MULTIPLIER environment var (Ben Noordhuis)
* unix: fix uv_cpu_info always returning UV_ENOTDIR on OpenBSD (Ben Davies)
* test: skip the pwd_shell test on IBMi (Xu Meng)
* win,tty: Change to restore cursor shape with uv_tty_reset() (erw7)
* win,tty: Added set cursor style to CSI sequences (erw7)
* test: handle EINTR, fix EOF check in poll test (Ben Noordhuis)
* unix: use socklen_t instead of size_t (Ben Noordhuis)
* doc: fix header file location (TK-one)
* unix: fix signal handle closing deferral (Ben Noordhuis)
* ibmi: set the amount of memory in use to zero (Xu Meng)
* zos: return on realloc failure in scandir() (Milad Farazmand)
* zos: fix scandir() error path NULL pointer deref (Ben Noordhuis)
2020.01.24, Version 1.34.2 (Stable), f868c9ab0c307525a16fff99fd21e32a6ebc3837
Changes since version 1.34.1:
......
......@@ -17,6 +17,8 @@ libuv is currently managed by the following individuals:
- GPG key: 9DFE AA5F 481B BF77 2D90 03CE D592 4925 2F8E C41A (pubkey-iwuzhere)
* **Jameson Nash** ([@vtjnash](https://github.com/vtjnash))
* **John Barboza** ([@jbarz](https://github.com/jbarz))
* **Kaoru Takanashi** ([@erw7](https://github.com/erw7))
- GPG Key: 5804 F999 8A92 2AFB A398 47A0 7183 5090 6134 887F (pubkey-erw7)
* **Richard Lau** ([@richardlau](https://github.com/richardlau))
- GPG key: C82F A3AE 1CBE DC6B E46B 9360 C43C EC45 C17A B93C (pubkey-richardlau)
* **Santiago Gimeno** ([@santigimeno](https://github.com/santigimeno))
......
......@@ -286,6 +286,7 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-timer.c \
test/test-tmpdir.c \
test/test-tty-duplicate-key.c \
test/test-tty-escape-sequence-processing.c \
test/test-tty.c \
test/test-udp-alloc-cb-fail.c \
test/test-udp-bind.c \
......
......@@ -347,6 +347,13 @@ $ make -C out
$ ./out/Debug/run-tests
```
Some tests are timing sensitive. Relaxing test timeouts may be necessary
on slow or overloaded machines:
```bash
$ env UV_TEST_TIMEOUT_MULTIPLIER=2 ./out/Debug/run-tests # 10s instead of 5s
```
#### Run one test
The list of all tests is in `test/test-list.h`.
......
......@@ -13,7 +13,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_PREREQ(2.57)
AC_INIT([libuv], [1.34.2], [https://github.com/libuv/libuv/issues])
AC_INIT([libuv], [1.35.0], [https://github.com/libuv/libuv/issues])
AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/libuv-extra-automake-flags.m4])
m4_include([m4/as_case.m4])
......
......@@ -244,6 +244,15 @@ API
.. c:function:: char** uv_setup_args(int argc, char** argv)
Store the program arguments. Required for getting / setting the process title.
Libuv may take ownership of the memory that `argv` points to. This function
should be called exactly once, at program start-up.
Example:
::
argv = uv_setup_args(argc, argv); /* May return a copy of argv. */
.. c:function:: int uv_get_process_title(char* buffer, size_t size)
......
......@@ -24,6 +24,8 @@ Public members
.. c:member:: int uv_pipe_t.ipc
Whether this pipe is suitable for handle passing between processes.
Only a connected pipe that will be passing the handles should have this flag
set, not the listening pipe that uv_accept is called on.
.. seealso:: The :c:type:`uv_stream_t` members also apply.
......@@ -35,7 +37,9 @@ API
Initialize a pipe handle. The `ipc` argument is a boolean to indicate if
this pipe will be used for handle passing between processes (which may
change the bytes on the wire).
change the bytes on the wire). Only a connected pipe that will be
passing the handles should have this flag set, not the listening pipe
that uv_accept is called on.
.. c:function:: int uv_pipe_open(uv_pipe_t* handle, uv_file file)
......
......@@ -60,6 +60,11 @@ API
Enable / disable TCP keep-alive. `delay` is the initial delay in seconds,
ignored when `enable` is zero.
After `delay` has been reached, 10 successive probes, each spaced 1 second
from the previous one, will still happen. If the connection is still lost
at the end of this procedure, then the handle is destroyed with a
``UV_ETIMEDOUT`` error passed to the corresponding callback.
.. c:function:: int uv_tcp_simultaneous_accepts(uv_tcp_t* handle, int enable)
Enable / disable simultaneous asynchronous accept requests that are
......
......@@ -42,6 +42,12 @@ Data types
* any traffic, in effect "stealing" the port from the previous listener.
*/
UV_UDP_REUSEADDR = 4
/*
* Indicates that the message was received by recvmmsg and that it's not at
* the beginning of the buffer allocated by alloc_cb - so the buffer provided
* must not be freed by the recv_cb callback.
*/
UV_UDP_MMSG_CHUNK = 8
};
.. c:type:: void (*uv_udp_send_cb)(uv_udp_send_t* req, int status)
......@@ -62,12 +68,13 @@ Data types
* `buf`: :c:type:`uv_buf_t` with the received data.
* `addr`: ``struct sockaddr*`` containing the address of the sender.
Can be NULL. Valid for the duration of the callback only.
* `flags`: One or more or'ed UV_UDP_* constants. Right now only
``UV_UDP_PARTIAL`` is used.
* `flags`: One or more or'ed UV_UDP_* constants.
The callee is responsible for freeing the buffer, libuv does not reuse it.
The buffer may be a null buffer (where `buf->base` == NULL and `buf->len` == 0)
on error.
on error. Don't free the buffer when the UV_UDP_MMSG_CHUNK flag is set.
The final callback receives the whole buffer (containing the first chunk)
with the UV_UDP_MMSG_CHUNK flag cleared.
.. note::
The receive callback will be called with `nread` == 0 and `addr` == NULL when there is
......
......@@ -605,7 +605,13 @@ enum uv_udp_flags {
* (provided they all set the flag) but only the last one to bind will receive
* any traffic, in effect "stealing" the port from the previous listener.
*/
UV_UDP_REUSEADDR = 4
UV_UDP_REUSEADDR = 4,
/*
* Indicates that the message was received by recvmmsg and that it's not at
* the beginning of the buffer allocated by alloc_cb - so the buffer provided
* must not be freed by the recv_cb callback.
*/
UV_UDP_MMSG_CHUNK = 8
};
typedef void (*uv_udp_send_cb)(uv_udp_send_t* req, int status);
......
......@@ -31,8 +31,8 @@
*/
#define UV_VERSION_MAJOR 1
#define UV_VERSION_MINOR 34
#define UV_VERSION_PATCH 2
#define UV_VERSION_MINOR 35
#define UV_VERSION_PATCH 0
#define UV_VERSION_IS_RELEASE 1
#define UV_VERSION_SUFFIX ""
......
......@@ -517,7 +517,7 @@ typedef struct {
/* eol conversion state */ \
unsigned char previous_eol; \
/* ansi parser state */ \
unsigned char ansi_parser_state; \
unsigned short ansi_parser_state; \
unsigned char ansi_csi_argc; \
unsigned short ansi_csi_argv[4]; \
COORD saved_position; \
......
......@@ -87,7 +87,7 @@ int uv_timer_start(uv_timer_t* handle,
handle->timer_cb = cb;
handle->timeout = clamped_timeout;
handle->repeat = repeat;
/* start_id is the second index to be compared in uv__timer_cmp() */
/* start_id is the second index to be compared in timer_less_than() */
handle->start_id = handle->loop->timer_counter++;
heap_insert(timer_heap(handle->loop),
......
......@@ -33,9 +33,12 @@
#include <string.h>
#include <unistd.h>
#ifdef __linux__
#include <sys/eventfd.h>
#endif
static void uv__async_send(uv_loop_t* loop);
static int uv__async_start(uv_loop_t* loop);
static int uv__async_eventfd(void);
int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) {
......@@ -190,36 +193,18 @@ static int uv__async_start(uv_loop_t* loop) {
if (loop->async_io_watcher.fd != -1)
return 0;
err = uv__async_eventfd();
if (err >= 0) {
pipefd[0] = err;
pipefd[1] = -1;
}
else if (err == UV_ENOSYS) {
err = uv__make_pipe(pipefd, UV__F_NONBLOCK);
#if defined(__linux__)
/* Save a file descriptor by opening one of the pipe descriptors as
* read/write through the procfs. That file descriptor can then
* function as both ends of the pipe.
*/
if (err == 0) {
char buf[32];
int fd;
snprintf(buf, sizeof(buf), "/proc/self/fd/%d", pipefd[0]);
fd = uv__open_cloexec(buf, O_RDWR);
if (fd >= 0) {
uv__close(pipefd[0]);
uv__close(pipefd[1]);
pipefd[0] = fd;
pipefd[1] = fd;
}
}
#endif
}
#ifdef __linux__
err = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
if (err < 0)
return UV__ERR(errno);
pipefd[0] = err;
pipefd[1] = -1;
#else
err = uv__make_pipe(pipefd, UV__F_NONBLOCK);
if (err < 0)
return err;
#endif
uv__io_init(&loop->async_io_watcher, uv__async_io, pipefd[0]);
uv__io_start(loop, &loop->async_io_watcher, POLLIN);
......@@ -253,46 +238,3 @@ void uv__async_stop(uv_loop_t* loop) {
uv__close(loop->async_io_watcher.fd);
loop->async_io_watcher.fd = -1;
}
static int uv__async_eventfd(void) {
#if defined(__linux__)
static int no_eventfd2;
static int no_eventfd;
int fd;
if (no_eventfd2)
goto skip_eventfd2;
fd = uv__eventfd2(0, UV__EFD_CLOEXEC | UV__EFD_NONBLOCK);
if (fd != -1)
return fd;
if (errno != ENOSYS)
return UV__ERR(errno);
no_eventfd2 = 1;
skip_eventfd2:
if (no_eventfd)
goto skip_eventfd;
fd = uv__eventfd(0);
if (fd != -1) {
uv__cloexec(fd, 1);
uv__nonblock(fd, 1);
return fd;
}
if (errno != ENOSYS)
return UV__ERR(errno);
no_eventfd = 1;
skip_eventfd:
#endif
return UV_ENOSYS;
}
......@@ -71,20 +71,12 @@ extern char** environ;
# include <sys/sysctl.h>
# include <sys/filio.h>
# include <sys/wait.h>
# if defined(__FreeBSD__) && __FreeBSD__ >= 10
# if defined(__FreeBSD__) || defined(__linux__)
# define uv__accept4 accept4
# endif
# if defined(__NetBSD__)
# define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
# endif
# if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || \
defined(__NetBSD__) || defined(__OpenBSD__)
# define UV__SOCK_NONBLOCK SOCK_NONBLOCK
# define UV__SOCK_CLOEXEC SOCK_CLOEXEC
# endif
# if !defined(F_DUP2FD_CLOEXEC) && defined(_F_DUP2FD_CLOEXEC)
# define F_DUP2FD_CLOEXEC _F_DUP2FD_CLOEXEC
# endif
#endif
#if defined(__ANDROID_API__) && __ANDROID_API__ < 21
......@@ -179,9 +171,7 @@ void uv_close(uv_handle_t* handle, uv_close_cb close_cb) {
case UV_SIGNAL:
uv__signal_close((uv_signal_t*) handle);
/* Signal handles may not be closed immediately. The signal code will
* itself close uv__make_close_pending whenever appropriate. */
return;
break;
default:
assert(0);
......@@ -246,6 +236,8 @@ int uv__getiovmax(void) {
static void uv__finish_close(uv_handle_t* handle) {
uv_signal_t* sh;
/* Note: while the handle is in the UV_HANDLE_CLOSING state now, it's still
* possible for it to be active in the sense that uv__is_active() returns
* true.
......@@ -268,7 +260,20 @@ static void uv__finish_close(uv_handle_t* handle) {
case UV_FS_EVENT:
case UV_FS_POLL:
case UV_POLL:
break;
case UV_SIGNAL:
/* If there are any caught signals "trapped" in the signal pipe,
* we can't call the close callback yet. Reinserting the handle
* into the closing queue makes the event loop spin but that's
* okay because we only need to deliver the pending events.
*/
sh = (uv_signal_t*) handle;
if (sh->caught_signals > sh->dispatched_signals) {
handle->flags ^= UV_HANDLE_CLOSED;
uv__make_close_pending(handle); /* Back into the queue. */
return;
}
break;
case UV_NAMED_PIPE:
......@@ -472,52 +477,32 @@ int uv__accept(int sockfd) {
int peerfd;
int err;
(void) &err;
assert(sockfd >= 0);
while (1) {
#if defined(__linux__) || \
(defined(__FreeBSD__) && __FreeBSD__ >= 10) || \
defined(__NetBSD__)
static int no_accept4;
if (no_accept4)
goto skip;
peerfd = uv__accept4(sockfd,
NULL,
NULL,
UV__SOCK_NONBLOCK|UV__SOCK_CLOEXEC);
if (peerfd != -1)
return peerfd;
if (errno == EINTR)
continue;
if (errno != ENOSYS)
return UV__ERR(errno);
no_accept4 = 1;
skip:
#endif
do
#ifdef uv__accept4
peerfd = uv__accept4(sockfd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
#else
peerfd = accept(sockfd, NULL, NULL);
if (peerfd == -1) {
if (errno == EINTR)
continue;
return UV__ERR(errno);
}
#endif
while (peerfd == -1 && errno == EINTR);
err = uv__cloexec(peerfd, 1);
if (err == 0)
err = uv__nonblock(peerfd, 1);
if (peerfd == -1)
return UV__ERR(errno);
if (err) {
uv__close(peerfd);
return err;
}
#ifndef uv__accept4
err = uv__cloexec(peerfd, 1);
if (err == 0)
err = uv__nonblock(peerfd, 1);
return peerfd;
if (err != 0) {
uv__close(peerfd);
return err;
}
#endif
return peerfd;
}
......@@ -533,7 +518,7 @@ int uv__close_nocancel(int fd) {
#if defined(__APPLE__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
#if defined(__LP64__)
#if defined(__LP64__) || defined(TARGET_OS_IPHONE)
extern int close$NOCANCEL(int);
return close$NOCANCEL(fd);
#else
......@@ -1031,54 +1016,30 @@ int uv__open_cloexec(const char* path, int flags) {
int uv__dup2_cloexec(int oldfd, int newfd) {
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
int r;
#if (defined(__FreeBSD__) && __FreeBSD__ >= 10) || defined(__NetBSD__)
r = dup3(oldfd, newfd, O_CLOEXEC);
if (r == -1)
return UV__ERR(errno);
return r;
#elif defined(__FreeBSD__) && defined(F_DUP2FD_CLOEXEC)
r = fcntl(oldfd, F_DUP2FD_CLOEXEC, newfd);
if (r != -1)
return r;
if (errno != EINVAL)
return UV__ERR(errno);
/* Fall through. */
#elif defined(__linux__)
static int no_dup3;
if (!no_dup3) {
do
r = uv__dup3(oldfd, newfd, O_CLOEXEC);
while (r == -1 && errno == EBUSY);
if (r != -1)
return r;
if (errno != ENOSYS)
return UV__ERR(errno);
/* Fall through. */
no_dup3 = 1;
}
#endif
{
int err;
do
r = dup2(oldfd, newfd);
#if defined(__linux__)
while (r == -1 && errno == EBUSY);
#else
while (0); /* Never retry. */
#endif
if (r == -1)
return UV__ERR(errno);
int err;
int r;
err = uv__cloexec(newfd, 1);
if (err) {
uv__close(newfd);
return err;
}
r = dup2(oldfd, newfd); /* Never retry. */
if (r == -1)
return UV__ERR(errno);
return r;
err = uv__cloexec(newfd, 1);
if (err != 0) {
uv__close(newfd);
return err;
}
return r;
#endif
}
......
......@@ -288,3 +288,28 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
uv__free(cp_times);
return 0;
}
int uv__sendmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags) {
#if __FreeBSD__ >= 11
return sendmmsg(fd, mmsg, vlen, flags);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__recvmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags,
struct timespec* timeout) {
#if __FreeBSD__ >= 11
return recvmmsg(fd, mmsg, vlen, flags, timeout);
#else
return errno = ENOSYS, -1;
#endif
}
......@@ -225,22 +225,7 @@ uint64_t uv_get_free_memory(void) {
if (get_ibmi_system_status(&rcvr))
return 0;
/* The amount of main storage, in kilobytes, in the system. */
uint64_t main_storage_size = rcvr.main_storage_size;
/* The current amount of storage in use for temporary objects.
* in millions (M) of bytes.
*/
uint64_t current_unprotected_storage_used =
rcvr.current_unprotected_storage_used * 1024ULL;
/* Current unprotected storage includes the storage used for memory
* and disks so it is possible to exceed the amount of main storage.
*/
if (main_storage_size <= current_unprotected_storage_used)
return 0ULL;
return (main_storage_size - current_unprotected_storage_used) * 1024ULL;
return (uint64_t)rcvr.main_storage_size * 1024ULL;
}
......
......@@ -28,9 +28,10 @@
#include <limits.h> /* _POSIX_PATH_MAX, PATH_MAX */
#include <stdlib.h> /* abort */
#include <string.h> /* strrchr */
#include <fcntl.h> /* O_CLOEXEC, may be */
#include <fcntl.h> /* O_CLOEXEC and O_NONBLOCK, if supported. */
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#if defined(__STRICT_ANSI__)
# define inline __inline
......@@ -284,13 +285,12 @@ int uv___stream_fd(const uv_stream_t* handle);
#define uv__stream_fd(handle) ((handle)->io_watcher.fd)
#endif /* defined(__APPLE__) */
#ifdef UV__O_NONBLOCK
# define UV__F_NONBLOCK UV__O_NONBLOCK
#ifdef O_NONBLOCK
# define UV__F_NONBLOCK O_NONBLOCK
#else
# define UV__F_NONBLOCK 1
#endif
int uv__make_socketpair(int fds[2], int flags);
int uv__make_pipe(int fds[2], int flags);
#if defined(__APPLE__)
......@@ -328,4 +328,27 @@ int uv__getsockpeername(const uv_handle_t* handle,
struct sockaddr* name,
int* namelen);
#if defined(__linux__) || \
defined(__FreeBSD__) || \
defined(__FreeBSD_kernel__)
#define HAVE_MMSG 1
struct uv__mmsghdr {
struct msghdr msg_hdr;
unsigned int msg_len;
};
int uv__recvmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags,
struct timespec* timeout);
int uv__sendmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags);
#else
#define HAVE_MMSG 0
#endif
#endif /* UV_UNIX_INTERNAL_H_ */
......@@ -29,6 +29,7 @@
#include <assert.h>
#include <errno.h>
#include <sys/inotify.h>
#include <sys/types.h>
#include <unistd.h>
......@@ -64,45 +65,17 @@ static void uv__inotify_read(uv_loop_t* loop,
static void maybe_free_watcher_list(struct watcher_list* w,
uv_loop_t* loop);
static int new_inotify_fd(void) {
int err;
int fd;
fd = uv__inotify_init1(UV__IN_NONBLOCK | UV__IN_CLOEXEC);
if (fd != -1)
return fd;
if (errno != ENOSYS)
return UV__ERR(errno);
fd = uv__inotify_init();
if (fd == -1)
return UV__ERR(errno);
err = uv__cloexec(fd, 1);
if (err == 0)
err = uv__nonblock(fd, 1);
if (err) {
uv__close(fd);
return err;
}
return fd;
}
static int init_inotify(uv_loop_t* loop) {
int err;
int fd;
if (loop->inotify_fd != -1)
return 0;
err = new_inotify_fd();
if (err < 0)
return err;
fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
if (fd < 0)
return UV__ERR(errno);
loop->inotify_fd = err;
loop->inotify_fd = fd;
uv__io_init(&loop->inotify_read_watcher, uv__inotify_read, loop->inotify_fd);
uv__io_start(loop, &loop->inotify_read_watcher, POLLIN);
......@@ -186,7 +159,7 @@ static void maybe_free_watcher_list(struct watcher_list* w, uv_loop_t* loop) {
if ((!w->iterating) && QUEUE_EMPTY(&w->watchers)) {
/* No watchers left for this path. Clean up. */
RB_REMOVE(watcher_root, CAST(&loop->inotify_watchers), w);
uv__inotify_rm_watch(loop->inotify_fd, w->wd);
inotify_rm_watch(loop->inotify_fd, w->wd);
uv__free(w);
}
}
......@@ -194,7 +167,7 @@ static void maybe_free_watcher_list(struct watcher_list* w, uv_loop_t* loop) {
static void uv__inotify_read(uv_loop_t* loop,
uv__io_t* dummy,
unsigned int events) {
const struct uv__inotify_event* e;
const struct inotify_event* e;
struct watcher_list* w;
uv_fs_event_t* h;
QUEUE queue;
......@@ -219,12 +192,12 @@ static void uv__inotify_read(uv_loop_t* loop,
/* Now we have one or more inotify_event structs. */
for (p = buf; p < buf + size; p += sizeof(*e) + e->len) {
e = (const struct uv__inotify_event*)p;
e = (const struct inotify_event*) p;
events = 0;
if (e->mask & (UV__IN_ATTRIB|UV__IN_MODIFY))
if (e->mask & (IN_ATTRIB|IN_MODIFY))
events |= UV_CHANGE;
if (e->mask & ~(UV__IN_ATTRIB|UV__IN_MODIFY))
if (e->mask & ~(IN_ATTRIB|IN_MODIFY))
events |= UV_RENAME;
w = find_watcher(loop, e->wd);
......@@ -290,16 +263,16 @@ int uv_fs_event_start(uv_fs_event_t* handle,
if (err)
return err;
events = UV__IN_ATTRIB
| UV__IN_CREATE
| UV__IN_MODIFY
| UV__IN_DELETE
| UV__IN_DELETE_SELF
| UV__IN_MOVE_SELF
| UV__IN_MOVED_FROM
| UV__IN_MOVED_TO;
events = IN_ATTRIB
| IN_CREATE
| IN_MODIFY
| IN_DELETE
| IN_DELETE_SELF
| IN_MOVE_SELF
| IN_MOVED_FROM
| IN_MOVED_TO;
wd = uv__inotify_add_watch(handle->loop->inotify_fd, path, events);
wd = inotify_add_watch(handle->loop->inotify_fd, path, events);
if (wd == -1)
return UV__ERR(errno);
......
......@@ -26,19 +26,6 @@
#include <sys/types.h>
#include <errno.h>
#if defined(__has_feature)
# if __has_feature(memory_sanitizer)
# define MSAN_ACTIVE 1
# include <sanitizer/msan_interface.h>
# endif
#endif
#if defined(__i386__)
# ifndef __NR_socketcall
# define __NR_socketcall 102
# endif
#endif
#if defined(__arm__)
# if defined(__thumb__) || defined(__ARM_EABI__)
# define UV_SYSCALL_BASE 0
......@@ -47,86 +34,6 @@
# endif
#endif /* __arm__ */
#ifndef __NR_accept4
# if defined(__x86_64__)
# define __NR_accept4 288
# elif defined(__i386__)
/* Nothing. Handled through socketcall(). */
# elif defined(__arm__)
# define __NR_accept4 (UV_SYSCALL_BASE + 366)
# endif
#endif /* __NR_accept4 */
#ifndef __NR_eventfd
# if defined(__x86_64__)
# define __NR_eventfd 284
# elif defined(__i386__)
# define __NR_eventfd 323
# elif defined(__arm__)
# define __NR_eventfd (UV_SYSCALL_BASE + 351)
# endif
#endif /* __NR_eventfd */
#ifndef __NR_eventfd2
# if defined(__x86_64__)
# define __NR_eventfd2 290
# elif defined(__i386__)
# define __NR_eventfd2 328
# elif defined(__arm__)
# define __NR_eventfd2 (UV_SYSCALL_BASE + 356)
# endif
#endif /* __NR_eventfd2 */
#ifndef __NR_inotify_init
# if defined(__x86_64__)
# define __NR_inotify_init 253
# elif defined(__i386__)
# define __NR_inotify_init 291
# elif defined(__arm__)
# define __NR_inotify_init (UV_SYSCALL_BASE + 316)
# endif
#endif /* __NR_inotify_init */
#ifndef __NR_inotify_init1
# if defined(__x86_64__)
# define __NR_inotify_init1 294
# elif defined(__i386__)
# define __NR_inotify_init1 332
# elif defined(__arm__)
# define __NR_inotify_init1 (UV_SYSCALL_BASE + 360)
# endif
#endif /* __NR_inotify_init1 */
#ifndef __NR_inotify_add_watch
# if defined(__x86_64__)
# define __NR_inotify_add_watch 254
# elif defined(__i386__)
# define __NR_inotify_add_watch 292
# elif defined(__arm__)
# define __NR_inotify_add_watch (UV_SYSCALL_BASE + 317)
# endif
#endif /* __NR_inotify_add_watch */
#ifndef __NR_inotify_rm_watch
# if defined(__x86_64__)
# define __NR_inotify_rm_watch 255
# elif defined(__i386__)
# define __NR_inotify_rm_watch 293
# elif defined(__arm__)
# define __NR_inotify_rm_watch (UV_SYSCALL_BASE + 318)
# endif
#endif /* __NR_inotify_rm_watch */
#ifndef __NR_pipe2
# if defined(__x86_64__)
# define __NR_pipe2 293
# elif defined(__i386__)
# define __NR_pipe2 331
# elif defined(__arm__)
# define __NR_pipe2 (UV_SYSCALL_BASE + 359)
# endif
#endif /* __NR_pipe2 */
#ifndef __NR_recvmmsg
# if defined(__x86_64__)
# define __NR_recvmmsg 299
......@@ -219,103 +126,7 @@
# endif
#endif /* __NR_getrandom */
int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) {
#if defined(__i386__)
unsigned long args[4];
int r;
args[0] = (unsigned long) fd;
args[1] = (unsigned long) addr;
args[2] = (unsigned long) addrlen;
args[3] = (unsigned long) flags;
r = syscall(__NR_socketcall, 18 /* SYS_ACCEPT4 */, args);
/* socketcall() raises EINVAL when SYS_ACCEPT4 is not supported but so does
* a bad flags argument. Try to distinguish between the two cases.
*/
if (r == -1)
if (errno == EINVAL)
if ((flags & ~(UV__SOCK_CLOEXEC|UV__SOCK_NONBLOCK)) == 0)
errno = ENOSYS;
return r;
#elif defined(__NR_accept4)
return syscall(__NR_accept4, fd, addr, addrlen, flags);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__eventfd(unsigned int count) {
#if defined(__NR_eventfd)
return syscall(__NR_eventfd, count);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__eventfd2(unsigned int count, int flags) {
#if defined(__NR_eventfd2)
return syscall(__NR_eventfd2, count, flags);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__inotify_init(void) {
#if defined(__NR_inotify_init)
return syscall(__NR_inotify_init);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__inotify_init1(int flags) {
#if defined(__NR_inotify_init1)
return syscall(__NR_inotify_init1, flags);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__inotify_add_watch(int fd, const char* path, uint32_t mask) {
#if defined(__NR_inotify_add_watch)
return syscall(__NR_inotify_add_watch, fd, path, mask);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__inotify_rm_watch(int fd, int32_t wd) {
#if defined(__NR_inotify_rm_watch)
return syscall(__NR_inotify_rm_watch, fd, wd);
#else
return errno = ENOSYS, -1;
#endif
}
int uv__pipe2(int pipefd[2], int flags) {
#if defined(__NR_pipe2)
int result;
result = syscall(__NR_pipe2, pipefd, flags);
#if MSAN_ACTIVE
if (!result)
__msan_unpoison(pipefd, sizeof(int[2]));
#endif
return result;
#else
return errno = ENOSYS, -1;
#endif
}
struct uv__mmsghdr;
int uv__sendmmsg(int fd,
struct uv__mmsghdr* mmsg,
......
......@@ -31,55 +31,6 @@
#include <sys/time.h>
#include <sys/socket.h>
#if defined(__alpha__)
# define UV__O_CLOEXEC 0x200000
#elif defined(__hppa__)
# define UV__O_CLOEXEC 0x200000
#elif defined(__sparc__)
# define UV__O_CLOEXEC 0x400000
#else
# define UV__O_CLOEXEC 0x80000
#endif
#if defined(__alpha__)
# define UV__O_NONBLOCK 0x4
#elif defined(__hppa__)
# define UV__O_NONBLOCK O_NONBLOCK
#elif defined(__mips__)
# define UV__O_NONBLOCK 0x80
#elif defined(__sparc__)
# define UV__O_NONBLOCK 0x4000
#else
# define UV__O_NONBLOCK 0x800
#endif
#define UV__EFD_CLOEXEC UV__O_CLOEXEC
#define UV__EFD_NONBLOCK UV__O_NONBLOCK
#define UV__IN_CLOEXEC UV__O_CLOEXEC
#define UV__IN_NONBLOCK UV__O_NONBLOCK
#define UV__SOCK_CLOEXEC UV__O_CLOEXEC
#if defined(SOCK_NONBLOCK)
# define UV__SOCK_NONBLOCK SOCK_NONBLOCK
#else
# define UV__SOCK_NONBLOCK UV__O_NONBLOCK
#endif
/* inotify flags */
#define UV__IN_ACCESS 0x001
#define UV__IN_MODIFY 0x002
#define UV__IN_ATTRIB 0x004
#define UV__IN_CLOSE_WRITE 0x008
#define UV__IN_CLOSE_NOWRITE 0x010
#define UV__IN_OPEN 0x020
#define UV__IN_MOVED_FROM 0x040
#define UV__IN_MOVED_TO 0x080
#define UV__IN_CREATE 0x100
#define UV__IN_DELETE 0x200
#define UV__IN_DELETE_SELF 0x400
#define UV__IN_MOVE_SELF 0x800
struct uv__statx_timestamp {
int64_t tv_sec;
uint32_t tv_nsec;
......@@ -110,36 +61,6 @@ struct uv__statx {
uint64_t unused1[14];
};
struct uv__inotify_event {
int32_t wd;
uint32_t mask;
uint32_t cookie;
uint32_t len;
/* char name[0]; */
};
struct uv__mmsghdr {
struct msghdr msg_hdr;
unsigned int msg_len;
};
int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags);
int uv__eventfd(unsigned int count);
int uv__eventfd2(unsigned int count, int flags);
int uv__inotify_init(void);
int uv__inotify_init1(int flags);
int uv__inotify_add_watch(int fd, const char* path, uint32_t mask);
int uv__inotify_rm_watch(int fd, int32_t wd);
int uv__pipe2(int pipefd[2], int flags);
int uv__recvmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags,
struct timespec* timeout);
int uv__sendmmsg(int fd,
struct uv__mmsghdr* mmsg,
unsigned int vlen,
unsigned int flags);
ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, int64_t offset);
ssize_t uv__pwritev(int fd, const struct iovec *iov, int iovcnt, int64_t offset);
int uv__dup3(int oldfd, int newfd, int flags);
......
......@@ -185,7 +185,7 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
char model[512];
int numcpus = 1;
int which[] = {CTL_HW,HW_MODEL};
int percpu[] = {CTL_HW,HW_CPUSPEED,0};
int percpu[] = {CTL_KERN,KERN_CPTIME2,0};
size_t size;
int i, j;
uv_cpu_info_t* cpu_info;
......@@ -206,17 +206,15 @@ int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) {
i = 0;
*count = numcpus;
which[1] = HW_CPUSPEED;
size = sizeof(cpuspeed);
if (sysctl(which, ARRAY_SIZE(percpu), &cpuspeed, &size, NULL, 0))
if (sysctl(which, ARRAY_SIZE(which), &cpuspeed, &size, NULL, 0))
goto error;
size = sizeof(info);
percpu[0] = CTL_KERN;
percpu[1] = KERN_CPTIME2;
for (i = 0; i < numcpus; i++) {
percpu[2] = i;
size = sizeof(info);
if (sysctl(which, ARRAY_SIZE(percpu), &info, &size, NULL, 0))
if (sysctl(percpu, ARRAY_SIZE(percpu), &info, &size, NULL, 0))
goto error;
cpu_info = &(*cpu_infos)[i];
......
......@@ -43,6 +43,7 @@ int scandir(const char* maindir, struct dirent*** namelist,
int (*compar)(const struct dirent**,
const struct dirent **)) {
struct dirent** nl;
struct dirent** nl_copy;
struct dirent* dirent;
unsigned count;
size_t allocated;
......@@ -62,19 +63,17 @@ int scandir(const char* maindir, struct dirent*** namelist,
if (!filter || filter(dirent)) {
struct dirent* copy;
copy = uv__malloc(sizeof(*copy));
if (!copy) {
while (count) {
dirent = nl[--count];
uv__free(dirent);
}
uv__free(nl);
closedir(mdir);
errno = ENOMEM;
return -1;
}
if (!copy)
goto error;
memcpy(copy, dirent, sizeof(*copy));
nl = uv__realloc(nl, sizeof(*copy) * (count + 1));
nl_copy = uv__realloc(nl, sizeof(*copy) * (count + 1));
if (nl_copy == NULL) {
uv__free(copy);
goto error;
}
nl = nl_copy;
nl[count++] = copy;
}
}
......@@ -86,6 +85,16 @@ int scandir(const char* maindir, struct dirent*** namelist,
*namelist = nl;
return count;
error:
while (count > 0) {
dirent = nl[--count];
uv__free(dirent);
}
uv__free(nl);
closedir(mdir);
errno = ENOMEM;
return -1;
}
......
......@@ -95,8 +95,12 @@ int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb) {
if (uv__stream_fd(handle) == -1)
return UV_EINVAL;
#if defined(__MVS__)
if (handle->ipc)
return UV_EINVAL;
#if defined(__MVS__) || defined(__PASE__)
/* On zOS, backlog=0 has undefined behaviour */
/* On IBMi PASE, backlog=0 leads to "Connection refused" error */
if (backlog == 0)
backlog = 1;
else if (backlog < 0)
......
......@@ -112,72 +112,64 @@ static void uv__chld(uv_signal_t* handle, int signum) {
}
int uv__make_socketpair(int fds[2], int flags) {
#if defined(__linux__)
static int no_cloexec;
if (no_cloexec)
goto skip;
if (socketpair(AF_UNIX, SOCK_STREAM | UV__SOCK_CLOEXEC | flags, 0, fds) == 0)
return 0;
/* Retry on EINVAL, it means SOCK_CLOEXEC is not supported.
* Anything else is a genuine error.
*/
if (errno != EINVAL)
static int uv__make_socketpair(int fds[2]) {
#if defined(__FreeBSD__) || defined(__linux__)
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fds))
return UV__ERR(errno);
no_cloexec = 1;
skip:
#endif
return 0;
#else
int err;
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds))
return UV__ERR(errno);
uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1);
err = uv__cloexec(fds[0], 1);
if (err == 0)
err = uv__cloexec(fds[1], 1);
if (flags & UV__F_NONBLOCK) {
uv__nonblock(fds[0], 1);
uv__nonblock(fds[1], 1);
if (err != 0) {
uv__close(fds[0]);
uv__close(fds[1]);
return UV__ERR(errno);
}
return 0;
#endif
}
int uv__make_pipe(int fds[2], int flags) {
#if defined(__linux__)
static int no_pipe2;
if (no_pipe2)
goto skip;
if (uv__pipe2(fds, flags | UV__O_CLOEXEC) == 0)
return 0;
if (errno != ENOSYS)
#if defined(__FreeBSD__) || defined(__linux__)
if (pipe2(fds, flags | O_CLOEXEC))
return UV__ERR(errno);
no_pipe2 = 1;
skip:
#endif
return 0;
#else
if (pipe(fds))
return UV__ERR(errno);
uv__cloexec(fds[0], 1);
uv__cloexec(fds[1], 1);
if (uv__cloexec(fds[0], 1))
goto fail;
if (uv__cloexec(fds[1], 1))
goto fail;
if (flags & UV__F_NONBLOCK) {
uv__nonblock(fds[0], 1);
uv__nonblock(fds[1], 1);
if (uv__nonblock(fds[0], 1))
goto fail;
if (uv__nonblock(fds[1], 1))
goto fail;
}
return 0;
fail:
uv__close(fds[0]);
uv__close(fds[1]);
return UV__ERR(errno);
#endif
}
......@@ -200,7 +192,7 @@ static int uv__process_init_stdio(uv_stdio_container_t* container, int fds[2]) {
if (container->data.stream->type != UV_NAMED_PIPE)
return UV_EINVAL;
else
return uv__make_socketpair(fds, 0);
return uv__make_socketpair(fds);
case UV_INHERIT_FD:
case UV_INHERIT_STREAM:
......
......@@ -24,17 +24,19 @@
#include <stdlib.h>
#include <string.h>
struct uv__process_title {
char* str;
size_t len; /* Length of the current process title. */
size_t cap; /* Maximum capacity. Computed once in uv_setup_args(). */
};
extern void uv__set_process_title(const char* title);
static uv_mutex_t process_title_mutex;
static uv_once_t process_title_mutex_once = UV_ONCE_INIT;
static struct uv__process_title process_title;
static void* args_mem;
static struct {
char* str;
size_t len;
} process_title;
static void init_process_title_mutex_once(void) {
uv_mutex_init(&process_title_mutex);
......@@ -42,6 +44,7 @@ static void init_process_title_mutex_once(void) {
char** uv_setup_args(int argc, char** argv) {
struct uv__process_title pt;
char** new_argv;
size_t size;
char* s;
......@@ -50,53 +53,69 @@ char** uv_setup_args(int argc, char** argv) {
if (argc <= 0)
return argv;
pt.str = argv[0];
pt.len = strlen(argv[0]);
pt.cap = pt.len + 1;
/* Calculate how much memory we need for the argv strings. */
size = 0;
for (i = 0; i < argc; i++)
size = pt.cap;
for (i = 1; i < argc; i++)
size += strlen(argv[i]) + 1;
#if defined(__MVS__)
/* argv is not adjacent. So just use argv[0] */
process_title.str = argv[0];
process_title.len = strlen(argv[0]);
#else
process_title.str = argv[0];
process_title.len = argv[argc - 1] + strlen(argv[argc - 1]) - argv[0];
assert(process_title.len + 1 == size); /* argv memory should be adjacent. */
#endif
/* Add space for the argv pointers. */
size += (argc + 1) * sizeof(char*);
new_argv = uv__malloc(size);
if (new_argv == NULL)
return argv;
args_mem = new_argv;
/* Copy over the strings and set up the pointer table. */
i = 0;
s = (char*) &new_argv[argc + 1];
for (i = 0; i < argc; i++) {
size = pt.cap;
goto loop;
for (/* empty */; i < argc; i++) {
size = strlen(argv[i]) + 1;
loop:
memcpy(s, argv[i], size);
new_argv[i] = s;
s += size;
}
new_argv[i] = NULL;
/* argv is not adjacent on z/os, we use just argv[0] on that platform. */
#ifndef __MVS__
pt.cap = argv[i - 1] + size - argv[0];
#endif
args_mem = new_argv;
process_title = pt;
return new_argv;
}
int uv_set_process_title(const char* title) {
struct uv__process_title* pt;
size_t len;
pt = &process_title;
len = strlen(title);
uv_once(&process_title_mutex_once, init_process_title_mutex_once);
uv_mutex_lock(&process_title_mutex);
if (process_title.len != 0) {
/* No need to terminate, byte after is always '\0'. */
strncpy(process_title.str, title, process_title.len);
uv__set_process_title(title);
if (len >= pt->cap) {
len = 0;
if (pt->cap > 0)
len = pt->cap - 1;
}
memcpy(pt->str, title, len);
memset(pt->str + len, '\0', pt->cap - len);
pt->len = len;
uv_mutex_unlock(&process_title_mutex);
return 0;
......
......@@ -331,16 +331,7 @@ int uv_signal_init(uv_loop_t* loop, uv_signal_t* handle) {
void uv__signal_close(uv_signal_t* handle) {
uv__signal_stop(handle);
/* If there are any caught signals "trapped" in the signal pipe, we can't
* call the close callback yet. Otherwise, add the handle to the finish_close
* queue.
*/
if (handle->caught_signals == handle->dispatched_signals) {
uv__make_close_pending((uv_handle_t*) handle);
}
}
......@@ -472,17 +463,6 @@ static void uv__signal_event(uv_loop_t* loop,
if (handle->flags & UV_SIGNAL_ONE_SHOT)
uv__signal_stop(handle);
/* If uv_close was called while there were caught signals that were not
* yet dispatched, the uv__finish_close was deferred. Make close pending
* now if this has happened.
*/
if (handle->caught_signals == handle->dispatched_signals) {
if (handle->signum == 0)
uv__handle_stop(handle);
if (handle->flags & UV_HANDLE_CLOSING)
uv__make_close_pending((uv_handle_t*) handle);
}
}
bytes -= end;
......@@ -572,6 +552,5 @@ static void uv__signal_stop(uv_signal_t* handle) {
uv__signal_unlock_and_unblock(&saved_sigmask);
handle->signum = 0;
if (handle->caught_signals == handle->dispatched_signals)
uv__handle_stop(handle);
uv__handle_stop(handle);
}
......@@ -379,8 +379,16 @@ int uv__tcp_keepalive(int fd, int on, unsigned int delay) {
return UV__ERR(errno);
#ifdef TCP_KEEPIDLE
if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
return UV__ERR(errno);
if (on) {
int intvl = 1; /* 1 second; same as default on Win32 */
int cnt = 10; /* 10 retries; same as hardcoded on Win32 */
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
return UV__ERR(errno);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
return UV__ERR(errno);
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
return UV__ERR(errno);
}
#endif
/* Solaris/SmartOS, if you don't support keep-alive,
......
......@@ -32,6 +32,8 @@
#endif
#include <sys/un.h>
#define UV__UDP_DGRAM_MAXSIZE (64 * 1024)
#if defined(IPV6_JOIN_GROUP) && !defined(IPV6_ADD_MEMBERSHIP)
# define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
#endif
......@@ -49,6 +51,36 @@ static int uv__udp_maybe_deferred_bind(uv_udp_t* handle,
int domain,
unsigned int flags);
#if HAVE_MMSG
#define UV__MMSG_MAXWIDTH 20
static int uv__udp_recvmmsg(uv_udp_t* handle, uv_buf_t* buf);
static void uv__udp_sendmmsg(uv_udp_t* handle);
static int uv__recvmmsg_avail;
static int uv__sendmmsg_avail;
static uv_once_t once = UV_ONCE_INIT;
static void uv__udp_mmsg_init(void) {
int ret;
int s;
s = uv__socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0)
return;
ret = uv__sendmmsg(s, NULL, 0, 0);
if (ret == 0 || errno != ENOSYS) {
uv__sendmmsg_avail = 1;
uv__recvmmsg_avail = 1;
} else {
ret = uv__recvmmsg(s, NULL, 0, 0, NULL);
if (ret == 0 || errno != ENOSYS)
uv__recvmmsg_avail = 1;
}
uv__close(s);
}
#endif
void uv__udp_close(uv_udp_t* handle) {
uv__io_close(handle->loop, &handle->io_watcher);
......@@ -148,6 +180,60 @@ static void uv__udp_io(uv_loop_t* loop, uv__io_t* w, unsigned int revents) {
}
}
#if HAVE_MMSG
static int uv__udp_recvmmsg(uv_udp_t* handle, uv_buf_t* buf) {
struct sockaddr_in6 peers[UV__MMSG_MAXWIDTH];
struct iovec iov[UV__MMSG_MAXWIDTH];
struct uv__mmsghdr msgs[UV__MMSG_MAXWIDTH];
ssize_t nread;
uv_buf_t chunk_buf;
size_t chunks;
int flags;
size_t k;
/* prepare structures for recvmmsg */
chunks = buf->len / UV__UDP_DGRAM_MAXSIZE;
if (chunks > ARRAY_SIZE(iov))
chunks = ARRAY_SIZE(iov);
for (k = 0; k < chunks; ++k) {
iov[k].iov_base = buf->base + k * UV__UDP_DGRAM_MAXSIZE;
iov[k].iov_len = UV__UDP_DGRAM_MAXSIZE;
msgs[k].msg_hdr.msg_iov = iov + k;
msgs[k].msg_hdr.msg_iovlen = 1;
msgs[k].msg_hdr.msg_name = peers + k;
msgs[k].msg_hdr.msg_namelen = sizeof(peers[0]);
}
do
nread = uv__recvmmsg(handle->io_watcher.fd, msgs, chunks, 0, NULL);
while (nread == -1 && errno == EINTR);
if (nread < 1) {
if (nread == 0 || errno == EAGAIN || errno == EWOULDBLOCK)
handle->recv_cb(handle, 0, buf, NULL, 0);
else
handle->recv_cb(handle, UV__ERR(errno), buf, NULL, 0);
} else {
/* count to zero, so the buffer base comes last */
for (k = nread; k > 0 && handle->recv_cb != NULL;) {
k--;
flags = 0;
if (msgs[k].msg_hdr.msg_flags & MSG_TRUNC)
flags |= UV_UDP_PARTIAL;
if (k != 0)
flags |= UV_UDP_MMSG_CHUNK;
chunk_buf = uv_buf_init(iov[k].iov_base, iov[k].iov_len);
handle->recv_cb(handle,
msgs[k].msg_len,
&chunk_buf,
msgs[k].msg_hdr.msg_name,
flags);
}
}
return nread;
}
#endif
static void uv__udp_recvmsg(uv_udp_t* handle) {
struct sockaddr_storage peer;
......@@ -167,13 +253,27 @@ static void uv__udp_recvmsg(uv_udp_t* handle) {
do {
buf = uv_buf_init(NULL, 0);
handle->alloc_cb((uv_handle_t*) handle, 64 * 1024, &buf);
handle->alloc_cb((uv_handle_t*) handle, UV__UDP_DGRAM_MAXSIZE, &buf);
if (buf.base == NULL || buf.len == 0) {
handle->recv_cb(handle, UV_ENOBUFS, &buf, NULL, 0);
return;
}
assert(buf.base != NULL);
#if HAVE_MMSG
uv_once(&once, uv__udp_mmsg_init);
if (uv__recvmmsg_avail) {
/* Returned space for more than 1 datagram, use it to receive
* multiple datagrams. */
if (buf.len >= 2 * UV__UDP_DGRAM_MAXSIZE) {
nread = uv__udp_recvmmsg(handle, &buf);
if (nread > 0)
count -= nread;
continue;
}
}
#endif
memset(&h, 0, sizeof(h));
memset(&peer, 0, sizeof(peer));
h.msg_name = &peer;
......@@ -199,21 +299,120 @@ static void uv__udp_recvmsg(uv_udp_t* handle) {
handle->recv_cb(handle, nread, &buf, (const struct sockaddr*) &peer, flags);
}
count--;
}
/* recv_cb callback may decide to pause or close the handle */
while (nread != -1
&& count-- > 0
&& count > 0
&& handle->io_watcher.fd != -1
&& handle->recv_cb != NULL);
}
#if HAVE_MMSG
static void uv__udp_sendmmsg(uv_udp_t* handle) {
uv_udp_send_t* req;
struct uv__mmsghdr h[UV__MMSG_MAXWIDTH];
struct uv__mmsghdr *p;
QUEUE* q;
ssize_t npkts;
size_t pkts;
size_t i;
if (QUEUE_EMPTY(&handle->write_queue))
return;
write_queue_drain:
for (pkts = 0, q = QUEUE_HEAD(&handle->write_queue);
pkts < UV__MMSG_MAXWIDTH && q != &handle->write_queue;
++pkts, q = QUEUE_HEAD(q)) {
assert(q != NULL);
req = QUEUE_DATA(q, uv_udp_send_t, queue);
assert(req != NULL);
p = &h[pkts];
memset(p, 0, sizeof(*p));
if (req->addr.ss_family == AF_UNSPEC) {
p->msg_hdr.msg_name = NULL;
p->msg_hdr.msg_namelen = 0;
} else {
p->msg_hdr.msg_name = &req->addr;
if (req->addr.ss_family == AF_INET6)
p->msg_hdr.msg_namelen = sizeof(struct sockaddr_in6);
else if (req->addr.ss_family == AF_INET)
p->msg_hdr.msg_namelen = sizeof(struct sockaddr_in);
else if (req->addr.ss_family == AF_UNIX)
p->msg_hdr.msg_namelen = sizeof(struct sockaddr_un);
else {
assert(0 && "unsupported address family");
abort();
}
}
h[pkts].msg_hdr.msg_iov = (struct iovec*) req->bufs;
h[pkts].msg_hdr.msg_iovlen = req->nbufs;
}
do
npkts = uv__sendmmsg(handle->io_watcher.fd, h, pkts, 0);
while (npkts == -1 && errno == EINTR);
if (npkts < 1) {
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == ENOBUFS)
return;
for (i = 0, q = QUEUE_HEAD(&handle->write_queue);
i < pkts && q != &handle->write_queue;
++i, q = QUEUE_HEAD(q)) {
assert(q != NULL);
req = QUEUE_DATA(q, uv_udp_send_t, queue);
assert(req != NULL);
req->status = UV__ERR(errno);
QUEUE_REMOVE(&req->queue);
QUEUE_INSERT_TAIL(&handle->write_completed_queue, &req->queue);
}
uv__io_feed(handle->loop, &handle->io_watcher);
return;
}
for (i = 0, q = QUEUE_HEAD(&handle->write_queue);
i < pkts && q != &handle->write_queue;
++i, q = QUEUE_HEAD(&handle->write_queue)) {
assert(q != NULL);
req = QUEUE_DATA(q, uv_udp_send_t, queue);
assert(req != NULL);
req->status = req->bufs[0].len;
/* Sending a datagram is an atomic operation: either all data
* is written or nothing is (and EMSGSIZE is raised). That is
* why we don't handle partial writes. Just pop the request
* off the write queue and onto the completed queue, done.
*/
QUEUE_REMOVE(&req->queue);
QUEUE_INSERT_TAIL(&handle->write_completed_queue, &req->queue);
}
/* couldn't batch everything, continue sending (jump to avoid stack growth) */
if (!QUEUE_EMPTY(&handle->write_queue))
goto write_queue_drain;
uv__io_feed(handle->loop, &handle->io_watcher);
return;
}
#endif
static void uv__udp_sendmsg(uv_udp_t* handle) {
uv_udp_send_t* req;
QUEUE* q;
struct msghdr h;
QUEUE* q;
ssize_t size;
#if HAVE_MMSG
uv_once(&once, uv__udp_mmsg_init);
if (uv__sendmmsg_avail) {
uv__udp_sendmmsg(handle);
return;
}
#endif
while (!QUEUE_EMPTY(&handle->write_queue)) {
q = QUEUE_HEAD(&handle->write_queue);
assert(q != NULL);
......@@ -263,7 +462,6 @@ static void uv__udp_sendmsg(uv_udp_t* handle) {
}
}
/* On the BSDs, SO_REUSEPORT implies SO_REUSEADDR but with some additional
* refinements for programs that use multicast.
*
......@@ -653,7 +851,7 @@ static int uv__udp_set_membership6(uv_udp_t* handle,
}
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__ANDROID__)
static int uv__udp_set_source_membership4(uv_udp_t* handle,
const struct sockaddr_in* multicast_addr,
const char* interface_addr,
......@@ -842,7 +1040,7 @@ int uv_udp_set_source_membership(uv_udp_t* handle,
const char* interface_addr,
const char* source_addr,
uv_membership membership) {
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__ANDROID__)
int err;
struct sockaddr_storage mcast_addr;
struct sockaddr_in* mcast_addr4;
......@@ -870,7 +1068,7 @@ int uv_udp_set_source_membership(uv_udp_t* handle,
src_addr6,
membership);
}
err = uv_ip4_addr(source_addr, 0, src_addr4);
if (err)
return err;
......@@ -889,7 +1087,7 @@ static int uv__setsockopt(uv_udp_t* handle,
int option4,
int option6,
const void* val,
size_t size) {
socklen_t size) {
int r;
if (handle->flags & UV_HANDLE_IPV6)
......@@ -1012,7 +1210,7 @@ int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) {
* and use the general uv__setsockopt_maybe_char call otherwise.
*/
#if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
defined(__MVS__)
defined(__MVS__)
if (handle->flags & UV_HANDLE_IPV6)
return uv__setsockopt(handle,
IP_MULTICAST_LOOP,
......
......@@ -251,7 +251,7 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
UnregisterWait(req->wait_handle);
req->wait_handle = INVALID_HANDLE_VALUE;
}
if (req->event_handle) {
if (req->event_handle != NULL) {
CloseHandle(req->event_handle);
req->event_handle = NULL;
}
......@@ -268,7 +268,7 @@ void uv_tcp_endgame(uv_loop_t* loop, uv_tcp_t* handle) {
UnregisterWait(handle->read_req.wait_handle);
handle->read_req.wait_handle = INVALID_HANDLE_VALUE;
}
if (handle->read_req.event_handle) {
if (handle->read_req.event_handle != NULL) {
CloseHandle(handle->read_req.event_handle);
handle->read_req.event_handle = NULL;
}
......@@ -428,6 +428,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) {
/* Prepare the overlapped structure. */
memset(&(req->u.io.overlapped), 0, sizeof(req->u.io.overlapped));
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
assert(req->event_handle != NULL);
req->u.io.overlapped.hEvent = (HANDLE) ((ULONG_PTR) req->event_handle | 1);
}
......@@ -466,7 +467,7 @@ static void uv_tcp_queue_accept(uv_tcp_t* handle, uv_tcp_accept_t* req) {
closesocket(accept_socket);
/* Destroy the event handle */
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
CloseHandle(req->u.io.overlapped.hEvent);
CloseHandle(req->event_handle);
req->event_handle = NULL;
}
}
......@@ -509,7 +510,7 @@ static void uv_tcp_queue_read(uv_loop_t* loop, uv_tcp_t* handle) {
/* Prepare the overlapped structure. */
memset(&(req->u.io.overlapped), 0, sizeof(req->u.io.overlapped));
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
assert(req->event_handle);
assert(req->event_handle != NULL);
req->u.io.overlapped.hEvent = (HANDLE) ((ULONG_PTR) req->event_handle | 1);
}
......@@ -612,8 +613,8 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
simultaneous_accepts = handle->flags & UV_HANDLE_TCP_SINGLE_ACCEPT ? 1
: uv_simultaneous_server_accepts;
if(!handle->tcp.serv.accept_reqs) {
handle->tcp.serv.accept_reqs = (uv_tcp_accept_t*)
if (handle->tcp.serv.accept_reqs == NULL) {
handle->tcp.serv.accept_reqs =
uv__malloc(uv_simultaneous_server_accepts * sizeof(uv_tcp_accept_t));
if (!handle->tcp.serv.accept_reqs) {
uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
......@@ -628,7 +629,7 @@ int uv_tcp_listen(uv_tcp_t* handle, int backlog, uv_connection_cb cb) {
req->wait_handle = INVALID_HANDLE_VALUE;
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
req->event_handle = CreateEvent(NULL, 0, 0, NULL);
if (!req->event_handle) {
if (req->event_handle == NULL) {
uv_fatal_error(GetLastError(), "CreateEvent");
}
} else {
......@@ -737,9 +738,9 @@ int uv_tcp_read_start(uv_tcp_t* handle, uv_alloc_cb alloc_cb,
* request pending. */
if (!(handle->flags & UV_HANDLE_READ_PENDING)) {
if (handle->flags & UV_HANDLE_EMULATE_IOCP &&
!handle->read_req.event_handle) {
handle->read_req.event_handle == NULL) {
handle->read_req.event_handle = CreateEvent(NULL, 0, 0, NULL);
if (!handle->read_req.event_handle) {
if (handle->read_req.event_handle == NULL) {
uv_fatal_error(GetLastError(), "CreateEvent");
}
}
......@@ -862,7 +863,7 @@ int uv_tcp_write(uv_loop_t* loop,
memset(&(req->u.io.overlapped), 0, sizeof(req->u.io.overlapped));
if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
req->event_handle = CreateEvent(NULL, 0, 0, NULL);
if (!req->event_handle) {
if (req->event_handle == NULL) {
uv_fatal_error(GetLastError(), "CreateEvent");
}
req->u.io.overlapped.hEvent = (HANDLE) ((ULONG_PTR) req->event_handle | 1);
......@@ -1080,7 +1081,7 @@ void uv_process_tcp_write_req(uv_loop_t* loop, uv_tcp_t* handle,
UnregisterWait(req->wait_handle);
req->wait_handle = INVALID_HANDLE_VALUE;
}
if (req->event_handle) {
if (req->event_handle != NULL) {
CloseHandle(req->event_handle);
req->event_handle = NULL;
}
......
......@@ -23,6 +23,7 @@ BENCHMARK_DECLARE (sizes)
BENCHMARK_DECLARE (loop_count)
BENCHMARK_DECLARE (loop_count_timed)
BENCHMARK_DECLARE (ping_pongs)
BENCHMARK_DECLARE (ping_udp)
BENCHMARK_DECLARE (tcp_write_batch)
BENCHMARK_DECLARE (tcp4_pound_100)
BENCHMARK_DECLARE (tcp4_pound_1000)
......
......@@ -218,8 +218,12 @@ static void send_listen_handles(uv_handle_type type,
}
else
ASSERT(0);
ASSERT(0 == uv_pipe_init(loop, &ctx.ipc_pipe, 1));
/* We need to initialize this pipe with ipc=0 - this is not a uv_pipe we'll
* be sending handles over, it's just for listening for new connections.
* If we accept a connection then the connected pipe must be initialized
* with ipc=1.
*/
ASSERT(0 == uv_pipe_init(loop, &ctx.ipc_pipe, 0));
ASSERT(0 == uv_pipe_bind(&ctx.ipc_pipe, IPC_PIPE_NAME));
ASSERT(0 == uv_listen((uv_stream_t*) &ctx.ipc_pipe, 128, ipc_connection_cb));
......
/* Copyright libuv project 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"
#include "task.h"
#include <stdlib.h>
#include <stdio.h>
/* Run the benchmark for this many ms */
#define TIME 5000
typedef struct {
int pongs;
int state;
uv_udp_t udp;
struct sockaddr_in server_addr;
} pinger_t;
typedef struct buf_s {
uv_buf_t uv_buf_t;
struct buf_s* next;
} buf_t;
static char PING[] = "PING\n";
static uv_loop_t* loop;
static int completed_pingers;
static unsigned long completed_pings;
static int64_t start_time;
static void buf_alloc(uv_handle_t* tcp, size_t size, uv_buf_t* buf) {
static char slab[64 * 1024];
buf->base = slab;
buf->len = sizeof(slab);
}
static void buf_free(const uv_buf_t* buf) {
}
static void pinger_close_cb(uv_handle_t* handle) {
pinger_t* pinger;
pinger = (pinger_t*)handle->data;
#if DEBUG
fprintf(stderr, "ping_pongs: %d roundtrips/s\n",
pinger->pongs / (TIME / 1000));
#endif
completed_pings += pinger->pongs;
completed_pingers++;
free(pinger);
}
static void pinger_write_ping(pinger_t* pinger) {
uv_buf_t buf;
int r;
buf = uv_buf_init(PING, sizeof(PING) - 1);
r = uv_udp_try_send(&pinger->udp, &buf, 1,
(const struct sockaddr*) &pinger->server_addr);
if (r < 0)
FATAL("uv_udp_send failed");
}
static void pinger_read_cb(uv_udp_t* udp,
ssize_t nread,
const uv_buf_t* buf,
const struct sockaddr* addr,
unsigned flags) {
ssize_t i;
pinger_t* pinger;
pinger = (pinger_t*)udp->data;
/* Now we count the pings */
for (i = 0; i < nread; i++) {
ASSERT(buf->base[i] == PING[pinger->state]);
pinger->state = (pinger->state + 1) % (sizeof(PING) - 1);
if (pinger->state == 0) {
pinger->pongs++;
if (uv_now(loop) - start_time > TIME) {
uv_close((uv_handle_t*)udp, pinger_close_cb);
break;
}
pinger_write_ping(pinger);
}
}
buf_free(buf);
}
static void udp_pinger_new(void) {
pinger_t* pinger = malloc(sizeof(*pinger));
int r;
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &pinger->server_addr));
pinger->state = 0;
pinger->pongs = 0;
/* Try to do NUM_PINGS ping-pongs (connection-less). */
r = uv_udp_init(loop, &pinger->udp);
ASSERT(r == 0);
pinger->udp.data = pinger;
/* Start pinging */
if (0 != uv_udp_recv_start(&pinger->udp, buf_alloc, pinger_read_cb)) {
FATAL("uv_udp_read_start failed");
}
pinger_write_ping(pinger);
}
static int ping_udp(unsigned pingers) {
unsigned i;
loop = uv_default_loop();
start_time = uv_now(loop);
for (i = 0; i < pingers; ++i) {
udp_pinger_new();
}
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(completed_pingers >= 1);
fprintf(stderr, "ping_pongs: %d pingers, ~ %lu roundtrips/s\n",
completed_pingers, completed_pings / (TIME/1000));
MAKE_VALGRIND_HAPPY();
return 0;
}
#define X(PINGERS) \
BENCHMARK_IMPL(ping_udp##PINGERS) {\
return ping_udp(PINGERS); \
}
X(1)
X(10)
X(100)
#undef X
......@@ -37,6 +37,7 @@ static uv_tcp_t tcpServer;
static uv_udp_t udpServer;
static uv_pipe_t pipeServer;
static uv_handle_t* server;
static uv_udp_send_t* send_freelist;
static void after_write(uv_write_t* req, int status);
static void after_read(uv_stream_t*, ssize_t nread, const uv_buf_t* buf);
......@@ -133,6 +134,14 @@ static void echo_alloc(uv_handle_t* handle,
buf->len = suggested_size;
}
static void slab_alloc(uv_handle_t* handle,
size_t suggested_size,
uv_buf_t* buf) {
/* up to 16 datagrams at once */
static char slab[16 * 64 * 1024];
buf->base = slab;
buf->len = sizeof(slab);
}
static void on_connection(uv_stream_t* server, int status) {
uv_stream_t* stream;
......@@ -178,35 +187,43 @@ static void on_server_close(uv_handle_t* handle) {
ASSERT(handle == server);
}
static uv_udp_send_t* send_alloc(void) {
uv_udp_send_t* req = send_freelist;
if (req != NULL)
send_freelist = req->data;
else
req = malloc(sizeof(*req));
return req;
}
static void on_send(uv_udp_send_t* req, int status);
static void on_send(uv_udp_send_t* req, int status) {
ASSERT(req != NULL);
ASSERT(status == 0);
req->data = send_freelist;
send_freelist = req;
}
static void on_recv(uv_udp_t* handle,
ssize_t nread,
const uv_buf_t* rcvbuf,
const struct sockaddr* addr,
unsigned flags) {
uv_udp_send_t* req;
uv_buf_t sndbuf;
if (nread == 0) {
/* Everything OK, but nothing read. */
return;
}
ASSERT(nread > 0);
ASSERT(addr->sa_family == AF_INET);
req = malloc(sizeof(*req));
uv_udp_send_t* req = send_alloc();
ASSERT(req != NULL);
sndbuf = *rcvbuf;
ASSERT(0 == uv_udp_send(req, handle, &sndbuf, 1, addr, on_send));
}
static void on_send(uv_udp_send_t* req, int status) {
ASSERT(status == 0);
free(req);
sndbuf = uv_buf_init(rcvbuf->base, nread);
ASSERT(0 <= uv_udp_send(req, handle, &sndbuf, 1, addr, on_send));
}
static int tcp4_echo_start(int port) {
struct sockaddr_in addr;
int r;
......@@ -277,8 +294,10 @@ static int tcp6_echo_start(int port) {
static int udp4_echo_start(int port) {
struct sockaddr_in addr;
int r;
ASSERT(0 == uv_ip4_addr("127.0.0.1", port, &addr));
server = (uv_handle_t*)&udpServer;
serverType = UDP;
......@@ -288,7 +307,13 @@ static int udp4_echo_start(int port) {
return 1;
}
r = uv_udp_recv_start(&udpServer, echo_alloc, on_recv);
r = uv_udp_bind(&udpServer, (const struct sockaddr*) &addr, 0);
if (r) {
fprintf(stderr, "uv_udp_bind: %s\n", uv_strerror(r));
return 1;
}
r = uv_udp_recv_start(&udpServer, slab_alloc, on_recv);
if (r) {
fprintf(stderr, "uv_udp_recv_start: %s\n", uv_strerror(r));
return 1;
......
......@@ -45,6 +45,7 @@ int ipc_helper_bind_twice(void);
int ipc_helper_send_zero(void);
int stdio_over_pipes_helper(void);
void spawn_stdin_stdout(void);
void process_title_big_argv(void);
int spawn_tcp_server_helper(void);
static int maybe_run_test(int argc, char **argv);
......@@ -210,7 +211,11 @@ static int maybe_run_test(int argc, char **argv) {
notify_parent_process();
ASSERT(sizeof(fd) == read(0, &fd, sizeof(fd)));
ASSERT(fd > 2);
# if defined(__PASE__) /* On IBMi PASE, write() returns 1 */
ASSERT(1 == write(fd, "x", 1));
# else
ASSERT(-1 == write(fd, "x", 1));
# endif /* !__PASE__ */
return 1;
}
......@@ -235,5 +240,11 @@ static int maybe_run_test(int argc, char **argv) {
}
#endif /* !_WIN32 */
if (strcmp(argv[1], "process_title_big_argv_helper") == 0) {
notify_parent_process();
process_title_big_argv();
return 0;
}
return run_test(argv[1], 0, 1);
}
......@@ -20,6 +20,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "runner.h"
......@@ -167,6 +168,7 @@ int run_test(const char* test,
process_info_t processes[1024];
process_info_t *main_proc;
task_entry_t* task;
int timeout_multiplier;
int process_count;
int result;
int status;
......@@ -249,7 +251,22 @@ int run_test(const char* test,
goto out;
}
result = process_wait(main_proc, 1, task->timeout);
timeout_multiplier = 1;
#ifndef _WIN32
do {
const char* var;
var = getenv("UV_TEST_TIMEOUT_MULTIPLIER");
if (var == NULL)
break;
timeout_multiplier = atoi(var);
if (timeout_multiplier <= 0)
timeout_multiplier = 1;
} while (0);
#endif
result = process_wait(main_proc, 1, task->timeout * timeout_multiplier);
if (result == -1) {
FATAL("process_wait failed");
} else if (result == -2) {
......
......@@ -199,8 +199,11 @@ TEST_IMPL(fs_copyfile) {
touch_file(dst, 0);
chmod(dst, S_IRUSR|S_IRGRP|S_IROTH); /* Sets file mode to 444 (read-only). */
r = uv_fs_copyfile(NULL, &req, fixture, dst, 0, NULL);
/* On IBMi PASE, qsecofr users can overwrite read-only files */
# ifndef __PASE__
ASSERT(req.result == UV_EACCES);
ASSERT(r == UV_EACCES);
# endif
uv_fs_req_cleanup(&req);
#endif
......
......@@ -285,6 +285,12 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle,
if (filename && strcmp(filename, file_prefix_in_subdir) == 0)
return;
#endif
/* It may happen that the "subdir" creation event is captured even though
* we started watching after its actual creation.
*/
if (strcmp(filename, "subdir") == 0)
return;
fs_multievent_cb_called++;
ASSERT(handle == &fs_event);
ASSERT(status == 0);
......@@ -300,11 +306,13 @@ static void fs_event_cb_dir_multi_file_in_subdir(uv_fs_event_t* handle,
sizeof(file_prefix_in_subdir) - 1) == 0);
#endif
if (fs_event_created + fs_event_removed == fs_event_file_count) {
if (fs_event_created == fs_event_file_count &&
fs_multievent_cb_called == fs_event_created) {
/* Once we've processed all create events, delete all files */
ASSERT(0 == uv_timer_start(&timer, fs_event_unlink_files_in_subdir, 1, 0));
} else if (fs_multievent_cb_called == 2 * fs_event_file_count) {
/* Once we've processed all create and delete events, stop watching */
ASSERT(fs_event_removed == fs_event_file_count);
uv_close((uv_handle_t*) &timer, close_cb);
uv_close((uv_handle_t*) handle, close_cb);
}
......
......@@ -309,6 +309,12 @@ static void chown_root_cb(uv_fs_t* req) {
# if defined(__CYGWIN__)
/* On Cygwin, uid 0 is invalid (no root). */
ASSERT(req->result == UV_EINVAL);
# elif defined(__PASE__)
/* On IBMi PASE, there is no root user. uid 0 is user qsecofr.
* User may grant qsecofr's privileges, including changing
* the file's ownership to uid 0.
*/
ASSERT(req->result == 0);
# else
ASSERT(req->result == UV_EPERM);
# endif
......@@ -2223,7 +2229,12 @@ int test_symlink_dir_impl(int type) {
#ifdef _WIN32
ASSERT(((uv_stat_t*)req.ptr)->st_size == strlen(test_dir + 4));
#else
# ifdef __PASE__
/* On IBMi PASE, st_size returns the length of the symlink itself. */
ASSERT(((uv_stat_t*)req.ptr)->st_size == strlen("test_dir_symlink"));
# else
ASSERT(((uv_stat_t*)req.ptr)->st_size == strlen(test_dir));
# endif
#endif
uv_fs_req_cleanup(&req);
......
......@@ -32,14 +32,13 @@ TEST_IMPL(get_memory) {
(unsigned long long) total_mem,
(unsigned long long) constrained_mem);
/* On IBMi PASE, the amount of memory in use includes storage used for
* memory and disks so it is possible to exceed the amount of main storage.
*/
#ifndef __PASE__
ASSERT(free_mem > 0);
#endif
ASSERT(total_mem > 0);
/* On IBMi PASE, the amount of memory in use is always zero. */
#ifdef __PASE__
ASSERT(total_mem == free_mem);
#else
ASSERT(total_mem > free_mem);
#endif
return 0;
}
......@@ -38,7 +38,9 @@ TEST_IMPL(get_passwd) {
ASSERT(pwd.shell == NULL);
#else
len = strlen(pwd.shell);
# ifndef __PASE__
ASSERT(len > 0);
# endif
#endif
len = strlen(pwd.homedir);
......
......@@ -56,10 +56,27 @@ TEST_DECLARE (tty_raw_cancel)
TEST_DECLARE (tty_duplicate_vt100_fn_key)
TEST_DECLARE (tty_duplicate_alt_modifier_key)
TEST_DECLARE (tty_composing_character)
TEST_DECLARE (tty_cursor_up)
TEST_DECLARE (tty_cursor_down)
TEST_DECLARE (tty_cursor_forward)
TEST_DECLARE (tty_cursor_back)
TEST_DECLARE (tty_cursor_next_line)
TEST_DECLARE (tty_cursor_previous_line)
TEST_DECLARE (tty_cursor_horizontal_move_absolute)
TEST_DECLARE (tty_cursor_move_absolute)
TEST_DECLARE (tty_hide_show_cursor)
TEST_DECLARE (tty_set_cursor_shape)
TEST_DECLARE (tty_erase)
TEST_DECLARE (tty_erase_line)
TEST_DECLARE (tty_set_style)
TEST_DECLARE (tty_save_restore_cursor_position)
TEST_DECLARE (tty_full_reset)
TEST_DECLARE (tty_escape_sequence_processing)
#endif
TEST_DECLARE (tty_file)
TEST_DECLARE (tty_pty)
TEST_DECLARE (stdio_over_pipes)
TEST_DECLARE (stdio_emulate_iocp)
TEST_DECLARE (ip6_pton)
TEST_DECLARE (connect_unspecified)
TEST_DECLARE (ipc_heavy_traffic_deadlock_bug)
......@@ -242,6 +259,7 @@ TEST_DECLARE (async_null_cb)
TEST_DECLARE (eintr_handling)
TEST_DECLARE (get_currentexe)
TEST_DECLARE (process_title)
TEST_DECLARE (process_title_big_argv)
TEST_DECLARE (process_title_threadsafe)
TEST_DECLARE (cwd_and_chdir)
TEST_DECLARE (get_memory)
......@@ -453,6 +471,7 @@ TEST_DECLARE (we_get_signal_one_shot)
TEST_DECLARE (we_get_signals_mixed)
TEST_DECLARE (signal_multiple_loops)
TEST_DECLARE (signal_pending_on_close)
TEST_DECLARE (signal_close_loop_alive)
TEST_DECLARE (closed_fd_events)
#endif
#ifdef __APPLE__
......@@ -545,10 +564,27 @@ TASK_LIST_START
TEST_ENTRY (tty_duplicate_vt100_fn_key)
TEST_ENTRY (tty_duplicate_alt_modifier_key)
TEST_ENTRY (tty_composing_character)
TEST_ENTRY (tty_cursor_up)
TEST_ENTRY (tty_cursor_down)
TEST_ENTRY (tty_cursor_forward)
TEST_ENTRY (tty_cursor_back)
TEST_ENTRY (tty_cursor_next_line)
TEST_ENTRY (tty_cursor_previous_line)
TEST_ENTRY (tty_cursor_horizontal_move_absolute)
TEST_ENTRY (tty_cursor_move_absolute)
TEST_ENTRY (tty_hide_show_cursor)
TEST_ENTRY (tty_set_cursor_shape)
TEST_ENTRY (tty_erase)
TEST_ENTRY (tty_erase_line)
TEST_ENTRY (tty_set_style)
TEST_ENTRY (tty_save_restore_cursor_position)
TEST_ENTRY (tty_full_reset)
TEST_ENTRY (tty_escape_sequence_processing)
#endif
TEST_ENTRY (tty_file)
TEST_ENTRY (tty_pty)
TEST_ENTRY (stdio_over_pipes)
TEST_ENTRY (stdio_emulate_iocp)
TEST_ENTRY (ip6_pton)
TEST_ENTRY (connect_unspecified)
TEST_ENTRY (ipc_heavy_traffic_deadlock_bug)
......@@ -684,11 +720,9 @@ TASK_LIST_START
TEST_ENTRY (udp_try_send)
TEST_ENTRY (udp_open)
TEST_HELPER (udp_open, udp4_echo_server)
TEST_ENTRY (udp_open_twice)
TEST_ENTRY (udp_open_bound)
TEST_ENTRY (udp_open_connect)
TEST_HELPER (udp_open_connect, udp4_echo_server)
#ifndef _WIN32
TEST_ENTRY (udp_send_unix)
#endif
......@@ -788,6 +822,7 @@ TASK_LIST_START
TEST_ENTRY (get_currentexe)
TEST_ENTRY (process_title)
TEST_ENTRY (process_title_big_argv)
TEST_ENTRY (process_title_threadsafe)
TEST_ENTRY (cwd_and_chdir)
......@@ -903,6 +938,7 @@ TASK_LIST_START
TEST_ENTRY (we_get_signals_mixed)
TEST_ENTRY (signal_multiple_loops)
TEST_ENTRY (signal_pending_on_close)
TEST_ENTRY (signal_close_loop_alive)
TEST_ENTRY (closed_fd_events)
#endif
......
......@@ -222,7 +222,10 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
case 1: {
/* Read a couple of bytes. */
static char buffer[74];
r = recv(context->sock, buffer, sizeof buffer, 0);
do
r = recv(context->sock, buffer, sizeof buffer, 0);
while (r == -1 && errno == EINTR);
ASSERT(r >= 0);
if (r > 0) {
......@@ -240,12 +243,16 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
case 3: {
/* Read until EAGAIN. */
static char buffer[931];
r = recv(context->sock, buffer, sizeof buffer, 0);
ASSERT(r >= 0);
while (r > 0) {
for (;;) {
do
r = recv(context->sock, buffer, sizeof buffer, 0);
while (r == -1 && errno == EINTR);
if (r <= 0)
break;
context->read += r;
r = recv(context->sock, buffer, sizeof buffer, 0);
}
if (r == 0) {
......@@ -301,7 +308,9 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
ASSERT(send_bytes > 0);
r = send(context->sock, buffer, send_bytes, 0);
do
r = send(context->sock, buffer, send_bytes, 0);
while (r == -1 && errno == EINTR);
if (r < 0) {
ASSERT(got_eagain());
......@@ -323,7 +332,9 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
int send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
ASSERT(send_bytes > 0);
r = send(context->sock, buffer, send_bytes, 0);
do
r = send(context->sock, buffer, send_bytes, 0);
while (r == -1 && errno == EINTR);
if (r < 0) {
ASSERT(got_eagain());
......@@ -339,12 +350,18 @@ static void connection_poll_cb(uv_poll_t* handle, int status, int events) {
send_bytes = MIN(TRANSFER_BYTES - context->sent, sizeof buffer);
ASSERT(send_bytes > 0);
r = send(context->sock, buffer, send_bytes, 0);
do
r = send(context->sock, buffer, send_bytes, 0);
while (r == -1 && errno == EINTR);
ASSERT(r != 0);
if (r < 0) {
ASSERT(got_eagain());
break;
}
if (r <= 0) break;
context->sent += r;
}
ASSERT(r > 0 || got_eagain());
break;
}
......
......@@ -74,3 +74,62 @@ TEST_IMPL(process_title) {
return 0;
}
static void exit_cb(uv_process_t* process, int64_t status, int signo) {
ASSERT(status == 0);
ASSERT(signo == 0);
uv_close((uv_handle_t*) process, NULL);
}
TEST_IMPL(process_title_big_argv) {
uv_process_options_t options;
uv_process_t process;
size_t exepath_size;
char exepath[1024];
char jumbo[512];
char* args[5];
#ifdef _WIN32
/* Remove once https://github.com/libuv/libuv/issues/2667 is fixed. */
uv_set_process_title("run-tests");
#endif
exepath_size = sizeof(exepath) - 1;
ASSERT(0 == uv_exepath(exepath, &exepath_size));
exepath[exepath_size] = '\0';
memset(jumbo, 'x', sizeof(jumbo) - 1);
jumbo[sizeof(jumbo) - 1] = '\0';
/* Note: need to pass three arguments, not two, otherwise
* run-tests.c thinks it's the name of a test to run.
*/
args[0] = exepath;
args[1] = "process_title_big_argv_helper";
args[2] = jumbo;
args[3] = jumbo;
args[4] = NULL;
memset(&options, 0, sizeof(options));
options.file = exepath;
options.args = args;
options.exit_cb = exit_cb;
ASSERT(0 == uv_spawn(uv_default_loop(), &process, &options));
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT));
MAKE_VALGRIND_HAPPY();
return 0;
}
/* Called by process_title_big_argv_helper. */
void process_title_big_argv(void) {
char buf[256] = "fail";
/* Return value deliberately ignored. */
uv_get_process_title(buf, sizeof(buf));
ASSERT(0 != strcmp(buf, "fail"));
}
......@@ -34,6 +34,11 @@ static char* buf;
static int close_cb_called;
static void stop_loop_cb(uv_signal_t* signal, int signum) {
ASSERT(signum == SIGPIPE);
uv_stop(signal->loop);
}
static void signal_cb(uv_signal_t* signal, int signum) {
ASSERT(0);
}
......@@ -91,4 +96,24 @@ TEST_IMPL(signal_pending_on_close) {
return 0;
}
#endif
\ No newline at end of file
TEST_IMPL(signal_close_loop_alive) {
ASSERT(0 == uv_loop_init(&loop));
ASSERT(0 == uv_signal_init(&loop, &signal_hdl));
ASSERT(0 == uv_signal_start(&signal_hdl, stop_loop_cb, SIGPIPE));
uv_unref((uv_handle_t*) &signal_hdl);
ASSERT(0 == uv_kill(uv_os_getpid(), SIGPIPE));
ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT));
uv_close((uv_handle_t*) &signal_hdl, close_cb);
ASSERT(1 == uv_loop_alive(&loop));
ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT));
ASSERT(0 == uv_loop_close(&loop));
ASSERT(1 == close_cb_called);
MAKE_VALGRIND_HAPPY();
return 0;
}
#endif
......@@ -1420,6 +1420,8 @@ TEST_IMPL(spawn_setuid_fails) {
int r;
/* if root, become nobody. */
/* On IBMi PASE, there is no nobody user. */
#ifndef __PASE__
uv_uid_t uid = getuid();
if (uid == 0) {
struct passwd* pw;
......@@ -1428,11 +1430,19 @@ TEST_IMPL(spawn_setuid_fails) {
ASSERT(0 == setgid(pw->pw_gid));
ASSERT(0 == setuid(pw->pw_uid));
}
#endif /* !__PASE__ */
init_process_options("spawn_helper1", fail_cb);
options.flags |= UV_PROCESS_SETUID;
/* On IBMi PASE, there is no root user. User may grant
* root-like privileges, including setting uid to 0.
*/
#if defined(__PASE__)
options.uid = -1;
#else
options.uid = 0;
#endif
/* These flags should be ignored on Unices. */
options.flags |= UV_PROCESS_WINDOWS_HIDE;
......@@ -1441,7 +1451,7 @@ TEST_IMPL(spawn_setuid_fails) {
options.flags |= UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS;
r = uv_spawn(uv_default_loop(), &process, &options);
#if defined(__CYGWIN__)
#if defined(__CYGWIN__) || defined(__PASE__)
ASSERT(r == UV_EINVAL);
#else
ASSERT(r == UV_EPERM);
......@@ -1461,6 +1471,8 @@ TEST_IMPL(spawn_setgid_fails) {
int r;
/* if root, become nobody. */
/* On IBMi PASE, there is no nobody user. */
#ifndef __PASE__
uv_uid_t uid = getuid();
if (uid == 0) {
struct passwd* pw;
......@@ -1469,18 +1481,22 @@ TEST_IMPL(spawn_setgid_fails) {
ASSERT(0 == setgid(pw->pw_gid));
ASSERT(0 == setuid(pw->pw_uid));
}
#endif /* !__PASE__ */
init_process_options("spawn_helper1", fail_cb);
options.flags |= UV_PROCESS_SETGID;
#if defined(__MVS__)
/* On IBMi PASE, there is no root user. User may grant
* root-like privileges, including setting gid to 0.
*/
#if defined(__MVS__) || defined(__PASE__)
options.gid = -1;
#else
options.gid = 0;
#endif
r = uv_spawn(uv_default_loop(), &process, &options);
#if defined(__CYGWIN__) || defined(__MVS__)
#if defined(__CYGWIN__) || defined(__MVS__) || defined(__PASE__)
ASSERT(r == UV_EINVAL);
#else
ASSERT(r == UV_EPERM);
......
......@@ -94,7 +94,7 @@ static void after_write(uv_write_t* req, int status) {
}
static void on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* rdbuf) {
static void on_read(uv_stream_t* pipe, ssize_t nread, const uv_buf_t* rdbuf) {
uv_write_t* req;
uv_buf_t wrbuf;
int r;
......@@ -103,11 +103,11 @@ static void on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* rdbuf) {
if (nread > 0) {
output_used += nread;
if (output_used == 12) {
if (output_used % 12 == 0) {
ASSERT(memcmp("hello world\n", output, 12) == 0);
wrbuf = uv_buf_init(output, output_used);
wrbuf = uv_buf_init(output, 12);
req = malloc(sizeof(*req));
r = uv_write(req, (uv_stream_t*)&in, &wrbuf, 1, after_write);
r = uv_write(req, (uv_stream_t*) &in, &wrbuf, 1, after_write);
ASSERT(r == 0);
}
}
......@@ -116,10 +116,10 @@ static void on_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* rdbuf) {
}
TEST_IMPL(stdio_over_pipes) {
static void test_stdio_over_pipes(int overlapped) {
int r;
uv_process_t process;
uv_stdio_container_t stdio[2];
uv_stdio_container_t stdio[3];
loop = uv_default_loop();
......@@ -129,11 +129,15 @@ TEST_IMPL(stdio_over_pipes) {
uv_pipe_init(loop, &in, 0);
options.stdio = stdio;
options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
options.stdio[0].data.stream = (uv_stream_t*)&in;
options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE;
options.stdio[1].data.stream = (uv_stream_t*)&out;
options.stdio_count = 2;
options.stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE |
(overlapped ? UV_OVERLAPPED_PIPE : 0);
options.stdio[0].data.stream = (uv_stream_t*) &in;
options.stdio[1].flags = UV_CREATE_PIPE | UV_WRITABLE_PIPE |
(overlapped ? UV_OVERLAPPED_PIPE : 0);
options.stdio[1].data.stream = (uv_stream_t*) &out;
options.stdio[2].flags = UV_INHERIT_FD;
options.stdio[2].data.fd = 2;
options.stdio_count = 3;
r = uv_spawn(loop, &process, &options);
ASSERT(r == 0);
......@@ -145,13 +149,22 @@ TEST_IMPL(stdio_over_pipes) {
ASSERT(r == 0);
ASSERT(on_read_cb_called > 1);
ASSERT(after_write_cb_called == 1);
ASSERT(after_write_cb_called == 2);
ASSERT(exit_cb_called == 1);
ASSERT(close_cb_called == 3);
ASSERT(memcmp("hello world\n", output, 12) == 0);
ASSERT(output_used == 12);
ASSERT(memcmp("hello world\nhello world\n", output, 24) == 0);
ASSERT(output_used == 24);
MAKE_VALGRIND_HAPPY();
}
TEST_IMPL(stdio_over_pipes) {
test_stdio_over_pipes(0);
return 0;
}
TEST_IMPL(stdio_emulate_iocp) {
test_stdio_over_pipes(1);
return 0;
}
......@@ -160,18 +173,19 @@ TEST_IMPL(stdio_over_pipes) {
static int on_pipe_read_called;
static int after_write_called;
static uv_pipe_t stdin_pipe;
static uv_pipe_t stdout_pipe;
static uv_pipe_t stdin_pipe1;
static uv_pipe_t stdout_pipe1;
static uv_pipe_t stdin_pipe2;
static uv_pipe_t stdout_pipe2;
static void on_pipe_read(uv_stream_t* tcp, ssize_t nread, const uv_buf_t* buf) {
static void on_pipe_read(uv_stream_t* pipe, ssize_t nread, const uv_buf_t* buf) {
ASSERT(nread > 0);
ASSERT(memcmp("hello world\n", buf->base, nread) == 0);
on_pipe_read_called++;
free(buf->base);
uv_close((uv_handle_t*)&stdin_pipe, close_cb);
uv_close((uv_handle_t*)&stdout_pipe, close_cb);
uv_read_stop(pipe);
}
......@@ -204,52 +218,81 @@ int stdio_over_pipes_helper(void) {
uv_write_t write_req[ARRAY_SIZE(buffers)];
uv_buf_t buf[ARRAY_SIZE(buffers)];
unsigned int i;
int j;
int r;
uv_loop_t* loop = uv_default_loop();
ASSERT(UV_NAMED_PIPE == uv_guess_handle(0));
ASSERT(UV_NAMED_PIPE == uv_guess_handle(1));
r = uv_pipe_init(loop, &stdin_pipe, 0);
r = uv_pipe_init(loop, &stdin_pipe1, 0);
ASSERT(r == 0);
r = uv_pipe_init(loop, &stdout_pipe1, 0);
ASSERT(r == 0);
r = uv_pipe_init(loop, &stdin_pipe2, 0);
ASSERT(r == 0);
r = uv_pipe_init(loop, &stdout_pipe, 0);
r = uv_pipe_init(loop, &stdout_pipe2, 0);
ASSERT(r == 0);
uv_pipe_open(&stdin_pipe, 0);
uv_pipe_open(&stdout_pipe, 1);
uv_pipe_open(&stdin_pipe1, 0);
uv_pipe_open(&stdout_pipe1, 1);
uv_pipe_open(&stdin_pipe2, 0);
uv_pipe_open(&stdout_pipe2, 1);
/* Unref both stdio handles to make sure that all writes complete. */
uv_unref((uv_handle_t*)&stdin_pipe);
uv_unref((uv_handle_t*)&stdout_pipe);
for (j = 0; j < 2; j++) {
/* Unref both stdio handles to make sure that all writes complete. */
uv_unref((uv_handle_t*) &stdin_pipe1);
uv_unref((uv_handle_t*) &stdout_pipe1);
uv_unref((uv_handle_t*) &stdin_pipe2);
uv_unref((uv_handle_t*) &stdout_pipe2);
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
buf[i] = uv_buf_init((char*)buffers[i], strlen(buffers[i]));
}
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
buf[i] = uv_buf_init((char*) buffers[i], strlen(buffers[i]));
}
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
r = uv_write(&write_req[i], (uv_stream_t*)&stdout_pipe, &buf[i], 1,
after_pipe_write);
ASSERT(r == 0);
}
for (i = 0; i < ARRAY_SIZE(buffers); i++) {
r = uv_write(&write_req[i],
(uv_stream_t*) (j == 0 ? &stdout_pipe1 : &stdout_pipe2),
&buf[i],
1,
after_pipe_write);
ASSERT(r == 0);
}
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT);
notify_parent_process();
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(after_write_called == 7);
ASSERT(on_pipe_read_called == 0);
ASSERT(close_cb_called == 0);
ASSERT(after_write_called == 7 * (j + 1));
ASSERT(on_pipe_read_called == j);
ASSERT(close_cb_called == 0);
uv_ref((uv_handle_t*)&stdout_pipe);
uv_ref((uv_handle_t*)&stdin_pipe);
uv_ref((uv_handle_t*) &stdout_pipe1);
uv_ref((uv_handle_t*) &stdin_pipe1);
uv_ref((uv_handle_t*) &stdout_pipe2);
uv_ref((uv_handle_t*) &stdin_pipe2);
r = uv_read_start((uv_stream_t*)&stdin_pipe, on_read_alloc, on_pipe_read);
ASSERT(r == 0);
r = uv_read_start((uv_stream_t*) (j == 0 ? &stdin_pipe1 : &stdin_pipe2),
on_read_alloc,
on_pipe_read);
ASSERT(r == 0);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(after_write_called == 7 * (j + 1));
ASSERT(on_pipe_read_called == j + 1);
ASSERT(close_cb_called == 0);
}
uv_close((uv_handle_t*)&stdin_pipe1, close_cb);
uv_close((uv_handle_t*)&stdout_pipe1, close_cb);
uv_close((uv_handle_t*)&stdin_pipe2, close_cb);
uv_close((uv_handle_t*)&stdout_pipe2, close_cb);
uv_run(loop, UV_RUN_DEFAULT);
ASSERT(after_write_called == 7);
ASSERT(on_pipe_read_called == 1);
ASSERT(close_cb_called == 2);
ASSERT(after_write_called == 14);
ASSERT(on_pipe_read_called == 2);
ASSERT(close_cb_called == 4);
MAKE_VALGRIND_HAPPY();
return 0;
......
......@@ -98,6 +98,10 @@ static void sv_recv_cb(uv_udp_t* handle,
TEST_IMPL(udp_connect) {
#if defined(__PASE__)
RETURN_SKIP(
"IBMi PASE's UDP connection can not be disconnected with AF_UNSPEC.");
#endif
uv_udp_send_t req;
struct sockaddr_in ext_addr;
struct sockaddr_in tmp_addr;
......
......@@ -41,11 +41,13 @@
static uv_udp_t client;
static uv_udp_t server;
static uv_udp_send_t req_;
static char data[10];
static uv_timer_t timeout;
static int send_cb_called;
static int recv_cb_called;
static int close_cb_called;
static uint16_t client_port;
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
static int can_ipv6_ipv4_dual(void) {
......@@ -83,12 +85,35 @@ static void send_cb(uv_udp_send_t* req, int status) {
send_cb_called++;
}
static int is_from_client(const struct sockaddr* addr) {
const struct sockaddr_in6* addr6;
char dst[256];
int r;
/* Debugging output, and filter out unwanted network traffic */
if (addr != NULL) {
ASSERT(addr->sa_family == AF_INET6);
addr6 = (struct sockaddr_in6*) addr;
r = uv_inet_ntop(addr->sa_family, &addr6->sin6_addr, dst, sizeof(dst));
if (r == 0)
printf("from [%.*s]:%d\n", (int) sizeof(dst), dst, addr6->sin6_port);
if (addr6->sin6_port != client_port)
return 0;
if (r != 0 || strcmp(dst, "::ffff:127.0.0.1"))
return 0;
}
return 1;
}
static void ipv6_recv_fail(uv_udp_t* handle,
ssize_t nread,
const uv_buf_t* buf,
const struct sockaddr* addr,
unsigned flags) {
printf("got %d %.*s\n", (int) nread, nread > 0 ? (int) nread : 0, buf->base);
if (!is_from_client(addr) || (nread == 0 && addr == NULL))
return;
ASSERT(0 && "this function should not have been called");
}
......@@ -99,10 +124,14 @@ static void ipv6_recv_ok(uv_udp_t* handle,
const struct sockaddr* addr,
unsigned flags) {
CHECK_HANDLE(handle);
ASSERT(nread >= 0);
if (nread)
recv_cb_called++;
printf("got %d %.*s\n", (int) nread, nread > 0 ? (int) nread : 0, buf->base);
if (!is_from_client(addr) || (nread == 0 && addr == NULL))
return;
ASSERT(nread == 9);
ASSERT(!memcmp(buf->base, data, 9));
recv_cb_called++;
}
......@@ -116,7 +145,10 @@ static void timeout_cb(uv_timer_t* timer) {
static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) {
struct sockaddr_in6 addr6;
struct sockaddr_in addr;
int addr6_len;
int addr_len;
uv_buf_t buf;
char dst[256];
int r;
ASSERT(0 == uv_ip6_addr("::0", TEST_PORT, &addr6));
......@@ -127,14 +159,25 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) {
r = uv_udp_bind(&server, (const struct sockaddr*) &addr6, bind_flags);
ASSERT(r == 0);
addr6_len = sizeof(addr6);
ASSERT(uv_udp_getsockname(&server, (struct sockaddr*) &addr6, &addr6_len) == 0);
ASSERT(uv_inet_ntop(addr6.sin6_family, &addr6.sin6_addr, dst, sizeof(dst)) == 0);
printf("on [%.*s]:%d\n", (int) sizeof(dst), dst, addr6.sin6_port);
r = uv_udp_recv_start(&server, alloc_cb, recv_cb);
ASSERT(r == 0);
r = uv_udp_init(uv_default_loop(), &client);
ASSERT(r == 0);
buf = uv_buf_init("PING", 4);
ASSERT(0 == uv_ip4_addr("127.0.0.1", TEST_PORT, &addr));
ASSERT(uv_inet_ntop(addr.sin_family, &addr.sin_addr, dst, sizeof(dst)) == 0);
printf("to [%.*s]:%d\n", (int) sizeof(dst), dst, addr.sin_port);
/* Create some unique data to send */
ASSERT(9 == snprintf(data, sizeof(data), "PING%5u", uv_os_getpid() & 0xFFFF));
buf = uv_buf_init(data, 9);
printf("sending %s\n", data);
r = uv_udp_send(&req_,
&client,
......@@ -144,6 +187,12 @@ static void do_test(uv_udp_recv_cb recv_cb, int bind_flags) {
send_cb);
ASSERT(r == 0);
addr_len = sizeof(addr);
ASSERT(uv_udp_getsockname(&client, (struct sockaddr*) &addr, &addr_len) == 0);
ASSERT(uv_inet_ntop(addr.sin_family, &addr.sin_addr, dst, sizeof(dst)) == 0);
printf("from [%.*s]:%d\n", (int) sizeof(dst), dst, addr.sin_port);
client_port = addr.sin_port;
r = uv_timer_init(uv_default_loop(), &timeout);
ASSERT(r == 0);
......@@ -180,6 +229,8 @@ TEST_IMPL(udp_dual_stack) {
do_test(ipv6_recv_ok, 0);
printf("recv_cb_called %d\n", recv_cb_called);
printf("send_cb_called %d\n", send_cb_called);
ASSERT(recv_cb_called == 1);
ASSERT(send_cb_called == 1);
......
......@@ -26,8 +26,9 @@
#include <errno.h>
/* NOTE: Number should be big enough to trigger this problem */
#if defined(__CYGWIN__) || defined(__MSYS__)
#if defined(__CYGWIN__) || defined(__MSYS__) || defined(__PASE__)
/* Cygwin crashes or hangs in socket() with too many AF_INET sockets. */
/* IBMi PASE timeout with too many AF_INET sockets. */
static uv_udp_t sockets[1250];
#else
static uv_udp_t sockets[2500];
......
......@@ -143,6 +143,7 @@
'test-timer-from-check.c',
'test-timer.c',
'test-tty-duplicate-key.c',
'test-tty-escape-sequence-processing.c',
'test-tty.c',
'test-udp-alloc-cb-fail.c',
'test-udp-bind.c',
......@@ -240,6 +241,7 @@
'benchmark-million-timers.c',
'benchmark-multi-accept.c',
'benchmark-ping-pongs.c',
'benchmark-ping-udp.c',
'benchmark-pound.c',
'benchmark-pump.c',
'benchmark-sizes.c',
......
......@@ -80,7 +80,7 @@ function get_netstring()
function get_libuv()
{
GIT_REPO="https://github.com/libuv/libuv.git"
GIT_TAG="v1.34.2"
GIT_TAG="v1.35.0"
DEST="deps/libuv"
get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}"
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论