Changes since version 1.38.1: * unix: use relaxed loads/stores for clock id (Ben Noordhuis) * build,win: link to user32.lib and advapi32.lib (George Zhao) * unix: squelch harmless valgrind warning (ssrlive) * include: fx c++ style comments warnings (Turbinya) * build,cmake: Change installation location on MinGW (erw7) * linux: use copy_file_range for uv_fs_copyfile when possible (Carter Li) * win,tcp: avoid reinserting a pending request ( * docs: improve the descriptions for get memory info (Juan Sebastian velez Posada) * test: add udp-mmsg test (Ryan Liptak) * udp: add uv_udp_using_recvmmsg query (Ryan Liptak) * doc: add more error constants (TK-one) * zos: fix potential event loop stall (Trevor Norris) * include: add internal fields struct to uv_loop_t (Trevor Norris) * core: add API to measure event loop idle time (Trevor Norris) * win,fs: use CreateDirectoryW instead of _wmkdir (Mustafa M) * win,nfc: fix integer comparison signedness (escherstair) * win,nfc: use * win,nfc: removed some unused variables (escherstair) * win,nfc: add missing return statement (escherstair) * win,nfc: disable clang-format for * darwin: use IOKit for uv_cpu_info (Evan Lucas) * test: fix thread race in process_title_threadsafe (Ben Noordhuis) * win,fs: avoid implicit access to _doserrno (Jameson Nash) * test: give hrtime test a custom 20s timeout (Jameson Nash) * build: add more failed test, for qemu version bump (gengjiawen) * unix: handle src, dest same in uv_fs_copyfile() (cjihrig) * unix: error when uv_setup_args() is not called (Ryan Liptak) * aix: protect uv_exepath() from uv_set_process_title() (Richard Lau) * fs: clobber req->path on uv_fs_mkstemp() error (tjarlama) * cmake: fix compile error C2001 on Chinese Windows (司徒玟琅) * test: avoid double evaluation in ASSERT_BASE macro (tjarlama) * tcp: fail instantly if local port is unbound (Bartosz Sosnowski) * doc: fix most sphinx warnings (Jameson Nash) * nfci: address some style nits (Jameson Nash) * unix: don't use _POSIX_PATH_MAX (Ben Noordhuis) -----BEGIN PGP SIGNATURE----- Comment: GPGTools - https://gpgtools.org iQIzBAABCgAdFiEElK42Z1xGTWS6+mjddDQ5C9vpucUFAl9EWmAACgkQdDQ5C9vp ucWLjxAAhKoJAz0z4MnTCn1wRss0QCIPQ+r7Be5QDbmLHW/z8maUy+WI0EO7TgKx 4XHDgdEXel7/EtKFgfLMVx087WuwTT45Xx4W5yxLF1CgRsu3zyy/rLpX/aT4uEIj 9QhZfY/s8H6LhJAyZwq/Km8UvG2Gbz01Y31aIXR6TdmBQ7MYr8JDu2KVYHMU0IZC pOju6C4JA09Z3PDtzxXAQj+xkzcWSgxkOTfRCmTbWcxsAhfUIse8zI84TW5STzGj 7E0jq6hgdFimzVYX7WucfPtg1ugrnip84TgTrcVkrB7YIv1K72f0ZCtorrSBATAZ ZhbCY8vo+wRpPXTbNvtnPk05S3XYO+ImmGktZUl4lI0BzpmaXpAy2XRTYSylYJnB zSp4CtJnaG68ZxHf4/29+Fh/J6aesxalPaP0VJaSV1WWV9sMxRwzAix0CX5w8ZqI TwMdOiAYqQPw77jN08ED+teUROiPtodraqkSeORS/5W4Wr3QApOdXUKJz0VQ+mpm +J+I0wKyBbBiD/Pe/zrbW/182bfbZBa1HYpLMmGTov0gaLNup5pz1iNdVm8i9+KG 3T9hSx+i36jbQ07MJG+UOunF3AqgUj7Sc5whrCVKcGpSThxN4dkSbMixGhBo86E1 LcaqOEo6teIE+aZYm1lVUdLG7ZbygwH6FRnqyUHVWKumQsygCno= =tL0f -----END PGP SIGNATURE----- Merge tag 'v1.39.0' into merge_1.39.0 PR-URL: https://github.com/libuv/libuv/pull/2969 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
345 lines
11 KiB
C
345 lines
11 KiB
C
/* 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.
|
|
*/
|
|
|
|
#ifndef UV_UNIX_INTERNAL_H_
|
|
#define UV_UNIX_INTERNAL_H_
|
|
|
|
#include "uv-common.h"
|
|
|
|
#include <assert.h>
|
|
#include <limits.h> /* _POSIX_PATH_MAX, PATH_MAX */
|
|
#include <stdlib.h> /* abort */
|
|
#include <string.h> /* strrchr */
|
|
#include <fcntl.h> /* O_CLOEXEC and O_NONBLOCK, if supported. */
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <sys/socket.h>
|
|
|
|
#if defined(__linux__)
|
|
# include "linux-syscalls.h"
|
|
#endif /* __linux__ */
|
|
|
|
#if defined(__MVS__)
|
|
# include "os390-syscalls.h"
|
|
#endif /* __MVS__ */
|
|
|
|
#if defined(__sun)
|
|
# include <sys/port.h>
|
|
# include <port.h>
|
|
#endif /* __sun */
|
|
|
|
#if defined(_AIX)
|
|
# define reqevents events
|
|
# define rtnevents revents
|
|
# include <sys/poll.h>
|
|
#else
|
|
# include <poll.h>
|
|
#endif /* _AIX */
|
|
|
|
#if defined(__APPLE__) && !TARGET_OS_IPHONE
|
|
# include <AvailabilityMacros.h>
|
|
#endif
|
|
|
|
#if defined(PATH_MAX)
|
|
# define UV__PATH_MAX PATH_MAX
|
|
#else
|
|
# define UV__PATH_MAX 8192
|
|
#endif
|
|
|
|
#if defined(__ANDROID__)
|
|
int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset);
|
|
# ifdef pthread_sigmask
|
|
# undef pthread_sigmask
|
|
# endif
|
|
# define pthread_sigmask(how, set, oldset) uv__pthread_sigmask(how, set, oldset)
|
|
#endif
|
|
|
|
#define ACCESS_ONCE(type, var) \
|
|
(*(volatile type*) &(var))
|
|
|
|
#define ROUND_UP(a, b) \
|
|
((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
|
|
|
|
#define UNREACHABLE() \
|
|
do { \
|
|
assert(0 && "unreachable code"); \
|
|
abort(); \
|
|
} \
|
|
while (0)
|
|
|
|
#define SAVE_ERRNO(block) \
|
|
do { \
|
|
int _saved_errno = errno; \
|
|
do { block; } while (0); \
|
|
errno = _saved_errno; \
|
|
} \
|
|
while (0)
|
|
|
|
/* The __clang__ and __INTEL_COMPILER checks are superfluous because they
|
|
* define __GNUC__. They are here to convey to you, dear reader, that these
|
|
* macros are enabled when compiling with clang or icc.
|
|
*/
|
|
#if defined(__clang__) || \
|
|
defined(__GNUC__) || \
|
|
defined(__INTEL_COMPILER)
|
|
# define UV_UNUSED(declaration) __attribute__((unused)) declaration
|
|
#else
|
|
# define UV_UNUSED(declaration) declaration
|
|
#endif
|
|
|
|
/* Leans on the fact that, on Linux, POLLRDHUP == EPOLLRDHUP. */
|
|
#ifdef POLLRDHUP
|
|
# define UV__POLLRDHUP POLLRDHUP
|
|
#else
|
|
# define UV__POLLRDHUP 0x2000
|
|
#endif
|
|
|
|
#ifdef POLLPRI
|
|
# define UV__POLLPRI POLLPRI
|
|
#else
|
|
# define UV__POLLPRI 0
|
|
#endif
|
|
|
|
#if !defined(O_CLOEXEC) && defined(__FreeBSD__)
|
|
/*
|
|
* It may be that we are just missing `__POSIX_VISIBLE >= 200809`.
|
|
* Try using fixed value const and give up, if it doesn't work
|
|
*/
|
|
# define O_CLOEXEC 0x00100000
|
|
#endif
|
|
|
|
typedef struct uv__stream_queued_fds_s uv__stream_queued_fds_t;
|
|
|
|
/* loop flags */
|
|
enum {
|
|
UV_LOOP_BLOCK_SIGPROF = 1
|
|
};
|
|
|
|
/* flags of excluding ifaddr */
|
|
enum {
|
|
UV__EXCLUDE_IFPHYS,
|
|
UV__EXCLUDE_IFADDR
|
|
};
|
|
|
|
typedef enum {
|
|
UV_CLOCK_PRECISE = 0, /* Use the highest resolution clock available. */
|
|
UV_CLOCK_FAST = 1 /* Use the fastest clock with <= 1ms granularity. */
|
|
} uv_clocktype_t;
|
|
|
|
struct uv__stream_queued_fds_s {
|
|
unsigned int size;
|
|
unsigned int offset;
|
|
int fds[1];
|
|
};
|
|
|
|
|
|
#if defined(_AIX) || \
|
|
defined(__APPLE__) || \
|
|
defined(__DragonFly__) || \
|
|
defined(__FreeBSD__) || \
|
|
defined(__FreeBSD_kernel__) || \
|
|
defined(__linux__) || \
|
|
defined(__OpenBSD__) || \
|
|
defined(__NetBSD__)
|
|
#define uv__cloexec uv__cloexec_ioctl
|
|
#define uv__nonblock uv__nonblock_ioctl
|
|
#else
|
|
#define uv__cloexec uv__cloexec_fcntl
|
|
#define uv__nonblock uv__nonblock_fcntl
|
|
#endif
|
|
|
|
/* On Linux, uv__nonblock_fcntl() and uv__nonblock_ioctl() do not commute
|
|
* when O_NDELAY is not equal to O_NONBLOCK. Case in point: linux/sparc32
|
|
* and linux/sparc64, where O_NDELAY is O_NONBLOCK + another bit.
|
|
*
|
|
* Libuv uses uv__nonblock_fcntl() directly sometimes so ensure that it
|
|
* commutes with uv__nonblock().
|
|
*/
|
|
#if defined(__linux__) && O_NDELAY != O_NONBLOCK
|
|
#undef uv__nonblock
|
|
#define uv__nonblock uv__nonblock_fcntl
|
|
#endif
|
|
|
|
/* core */
|
|
int uv__cloexec_ioctl(int fd, int set);
|
|
int uv__cloexec_fcntl(int fd, int set);
|
|
int uv__nonblock_ioctl(int fd, int set);
|
|
int uv__nonblock_fcntl(int fd, int set);
|
|
int uv__close(int fd); /* preserves errno */
|
|
int uv__close_nocheckstdio(int fd);
|
|
int uv__close_nocancel(int fd);
|
|
int uv__socket(int domain, int type, int protocol);
|
|
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags);
|
|
void uv__make_close_pending(uv_handle_t* handle);
|
|
int uv__getiovmax(void);
|
|
|
|
void uv__io_init(uv__io_t* w, uv__io_cb cb, int fd);
|
|
void uv__io_start(uv_loop_t* loop, uv__io_t* w, unsigned int events);
|
|
void uv__io_stop(uv_loop_t* loop, uv__io_t* w, unsigned int events);
|
|
void uv__io_close(uv_loop_t* loop, uv__io_t* w);
|
|
void uv__io_feed(uv_loop_t* loop, uv__io_t* w);
|
|
int uv__io_active(const uv__io_t* w, unsigned int events);
|
|
int uv__io_check_fd(uv_loop_t* loop, int fd);
|
|
void uv__io_poll(uv_loop_t* loop, int timeout); /* in milliseconds or -1 */
|
|
int uv__io_fork(uv_loop_t* loop);
|
|
int uv__fd_exists(uv_loop_t* loop, int fd);
|
|
|
|
/* async */
|
|
void uv__async_stop(uv_loop_t* loop);
|
|
int uv__async_fork(uv_loop_t* loop);
|
|
|
|
|
|
/* loop */
|
|
void uv__run_idle(uv_loop_t* loop);
|
|
void uv__run_check(uv_loop_t* loop);
|
|
void uv__run_prepare(uv_loop_t* loop);
|
|
|
|
/* stream */
|
|
void uv__stream_init(uv_loop_t* loop, uv_stream_t* stream,
|
|
uv_handle_type type);
|
|
int uv__stream_open(uv_stream_t*, int fd, int flags);
|
|
void uv__stream_destroy(uv_stream_t* stream);
|
|
#if defined(__APPLE__)
|
|
int uv__stream_try_select(uv_stream_t* stream, int* fd);
|
|
#endif /* defined(__APPLE__) */
|
|
void uv__server_io(uv_loop_t* loop, uv__io_t* w, unsigned int events);
|
|
int uv__accept(int sockfd);
|
|
int uv__dup2_cloexec(int oldfd, int newfd);
|
|
int uv__open_cloexec(const char* path, int flags);
|
|
|
|
/* tcp */
|
|
int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb);
|
|
int uv__tcp_nodelay(int fd, int on);
|
|
int uv__tcp_keepalive(int fd, int on, unsigned int delay);
|
|
|
|
/* pipe */
|
|
int uv_pipe_listen(uv_pipe_t* handle, int backlog, uv_connection_cb cb);
|
|
|
|
/* signal */
|
|
void uv__signal_close(uv_signal_t* handle);
|
|
void uv__signal_global_once_init(void);
|
|
void uv__signal_loop_cleanup(uv_loop_t* loop);
|
|
int uv__signal_loop_fork(uv_loop_t* loop);
|
|
|
|
/* platform specific */
|
|
uint64_t uv__hrtime(uv_clocktype_t type);
|
|
int uv__kqueue_init(uv_loop_t* loop);
|
|
int uv__platform_loop_init(uv_loop_t* loop);
|
|
void uv__platform_loop_delete(uv_loop_t* loop);
|
|
void uv__platform_invalidate_fd(uv_loop_t* loop, int fd);
|
|
|
|
/* various */
|
|
void uv__async_close(uv_async_t* handle);
|
|
void uv__fs_event_close(uv_fs_event_t* handle);
|
|
void uv__pipe_close(uv_pipe_t* handle);
|
|
void uv__poll_close(uv_poll_t* handle);
|
|
void uv__process_close(uv_process_t* handle);
|
|
void uv__stream_close(uv_stream_t* handle);
|
|
void uv__tcp_close(uv_tcp_t* handle);
|
|
void uv__udp_close(uv_udp_t* handle);
|
|
void uv__udp_finish_close(uv_udp_t* handle);
|
|
uv_handle_type uv__handle_type(int fd);
|
|
FILE* uv__open_file(const char* path);
|
|
int uv__getpwuid_r(uv_passwd_t* pwd);
|
|
int uv__search_path(const char* prog, char* buf, size_t* buflen);
|
|
|
|
/* random */
|
|
int uv__random_devurandom(void* buf, size_t buflen);
|
|
int uv__random_getrandom(void* buf, size_t buflen);
|
|
int uv__random_getentropy(void* buf, size_t buflen);
|
|
int uv__random_readpath(const char* path, void* buf, size_t buflen);
|
|
int uv__random_sysctl(void* buf, size_t buflen);
|
|
|
|
#if defined(__APPLE__)
|
|
int uv___stream_fd(const uv_stream_t* handle);
|
|
#define uv__stream_fd(handle) (uv___stream_fd((const uv_stream_t*) (handle)))
|
|
#else
|
|
#define uv__stream_fd(handle) ((handle)->io_watcher.fd)
|
|
#endif /* defined(__APPLE__) */
|
|
|
|
#ifdef O_NONBLOCK
|
|
# define UV__F_NONBLOCK O_NONBLOCK
|
|
#else
|
|
# define UV__F_NONBLOCK 1
|
|
#endif
|
|
|
|
int uv__make_pipe(int fds[2], int flags);
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
int uv__fsevents_init(uv_fs_event_t* handle);
|
|
int uv__fsevents_close(uv_fs_event_t* handle);
|
|
void uv__fsevents_loop_delete(uv_loop_t* loop);
|
|
|
|
#endif /* defined(__APPLE__) */
|
|
|
|
UV_UNUSED(static void uv__update_time(uv_loop_t* loop)) {
|
|
/* Use a fast time source if available. We only need millisecond precision.
|
|
*/
|
|
loop->time = uv__hrtime(UV_CLOCK_FAST) / 1000000;
|
|
}
|
|
|
|
UV_UNUSED(static char* uv__basename_r(const char* path)) {
|
|
char* s;
|
|
|
|
s = strrchr(path, '/');
|
|
if (s == NULL)
|
|
return (char*) path;
|
|
|
|
return s + 1;
|
|
}
|
|
|
|
#if defined(__linux__)
|
|
int uv__inotify_fork(uv_loop_t* loop, void* old_watchers);
|
|
#endif
|
|
|
|
typedef int (*uv__peersockfunc)(int, struct sockaddr*, socklen_t*);
|
|
|
|
int uv__getsockpeername(const uv_handle_t* handle,
|
|
uv__peersockfunc func,
|
|
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_ */
|