Go to the documentation of this file.
31 #include <sys/types.h>
34 #include <sys/ioctl.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
41 #include <sys/resource.h>
43 #include <sys/utsname.h>
47 # include <sys/filio.h>
48 # include <sys/types.h>
49 # include <sys/wait.h>
52 #if defined(__APPLE__)
53 # include <sys/filio.h>
57 #if defined(__APPLE__) && !TARGET_OS_IPHONE
58 # include <crt_externs.h>
59 # include <mach-o/dyld.h>
60 # define environ (*_NSGetEnviron())
66 #if defined(__DragonFly__) || \
67 defined(__FreeBSD__) || \
68 defined(__FreeBSD_kernel__) || \
69 defined(__NetBSD__) || \
71 # include <sys/sysctl.h>
72 # include <sys/filio.h>
73 # include <sys/wait.h>
74 # if defined(__FreeBSD__)
75 # define uv__accept4 accept4
77 # if defined(__NetBSD__)
78 # define uv__accept4(a, b, c, d) paccept((a), (b), (c), NULL, (d))
82 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
87 #include <sys/ioctl.h>
90 #if defined(__linux__)
91 # include <sys/syscall.h>
92 # define uv__accept4 accept4
100 sizeof(((
struct iovec*) 0)->iov_base));
102 sizeof(((
struct iovec*) 0)->iov_len));
192 if (
handle->type == UV_TCP ||
handle->type == UV_NAMED_PIPE)
194 else if (
handle->type == UV_UDP)
199 len =
sizeof(*value);
202 r = getsockopt(fd, SOL_SOCKET, optname,
value, &
len);
204 r = setsockopt(fd, SOL_SOCKET, optname, (
const void*)
value,
len);
222 #elif defined(_SC_IOV_MAX)
223 static int iovmax = -1;
225 iovmax = sysconf(_SC_IOV_MAX);
230 if (iovmax == -1) iovmax = 1;
273 if (sh->caught_signals > sh->dispatched_signals) {
308 p =
loop->closing_handles;
309 loop->closing_handles = NULL;
325 return loop->backend_fd;
330 if (
loop->stop_flag != 0)
342 if (
loop->closing_handles)
352 loop->closing_handles != NULL;
368 uv__update_time(
loop);
370 while (
r != 0 &&
loop->stop_flag == 0) {
371 uv__update_time(
loop);
394 uv__update_time(
loop);
406 if (
loop->stop_flag != 0)
414 uv__update_time(
loop);
428 #if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
450 #if defined(SO_NOSIGPIPE)
453 setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on,
sizeof(on));
469 fp = fdopen(fd,
"r");
486 peerfd = uv__accept4(sockfd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
488 peerfd = accept(sockfd, NULL, NULL);
490 while (peerfd == -1 && errno == EINTR);
519 #if defined(__APPLE__)
520 #pragma GCC diagnostic push
521 #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
522 #if defined(__LP64__) || TARGET_OS_IPHONE
523 extern int close$NOCANCEL(
int);
524 return close$NOCANCEL(fd);
526 extern int close$NOCANCEL$UNIX2003(
int);
527 return close$NOCANCEL$UNIX2003(fd);
529 #pragma GCC diagnostic pop
530 #elif defined(__linux__)
548 if (rc == UV_EINTR || rc ==
UV__ERR(EINPROGRESS))
558 assert(fd > STDERR_FILENO);
570 r = ioctl(fd, FIONBIO, &
set);
571 while (
r == -1 && errno == EINTR);
580 #if !defined(__CYGWIN__) && !defined(__MSYS__) && !defined(__HAIKU__)
585 r = ioctl(fd,
set ? FIOCLEX : FIONCLEX);
586 while (
r == -1 && errno == EINTR);
601 r = fcntl(fd, F_GETFL);
602 while (
r == -1 && errno == EINTR);
608 if (!!(
r & O_NONBLOCK) == !!
set)
617 r = fcntl(fd, F_SETFL,
flags);
618 while (
r == -1 && errno == EINTR);
632 r = fcntl(fd, F_GETFD);
633 while (
r == -1 && errno == EINTR);
639 if (!!(
r & FD_CLOEXEC) == !!
set)
648 r = fcntl(fd, F_SETFD,
flags);
649 while (
r == -1 && errno == EINTR);
659 struct cmsghdr* cmsg;
663 #if defined(__linux__)
664 static int no_msg_cmsg_cloexec;
665 if (no_msg_cmsg_cloexec == 0) {
666 rc = recvmsg(fd,
msg,
flags | 0x40000000);
674 no_msg_cmsg_cloexec = 1;
683 if (
msg->msg_controllen == 0)
685 for (cmsg = CMSG_FIRSTHDR(
msg); cmsg != NULL; cmsg = CMSG_NXTHDR(
msg, cmsg))
686 if (cmsg->cmsg_type == SCM_RIGHTS)
687 for (pfd = (
int*) CMSG_DATA(cmsg),
688 end = (
int*) ((
char*) cmsg + cmsg->cmsg_len);
820 void* fake_watcher_list;
821 void* fake_watcher_count;
822 unsigned int nwatchers;
825 if (len <= loop->nwatchers)
829 if (
loop->watchers != NULL) {
830 fake_watcher_list =
loop->watchers[
loop->nwatchers];
831 fake_watcher_count =
loop->watchers[
loop->nwatchers + 1];
833 fake_watcher_list = NULL;
834 fake_watcher_count = NULL;
839 (nwatchers + 2) *
sizeof(
loop->watchers[0]));
841 if (watchers == NULL)
843 for (
i =
loop->nwatchers;
i < nwatchers;
i++)
845 watchers[nwatchers] = fake_watcher_list;
846 watchers[nwatchers + 1] = fake_watcher_count;
848 loop->watchers = watchers;
849 loop->nwatchers = nwatchers;
863 #if defined(UV_HAVE_KQUEUE)
874 assert(w->
fd < INT_MAX);
891 if (
loop->watchers[w->
fd] == NULL) {
892 loop->watchers[w->
fd] = w;
908 if ((
unsigned) w->
fd >=
loop->nwatchers)
917 if (
loop->watchers[w->
fd] != NULL) {
918 assert(
loop->watchers[w->
fd] == w);
919 assert(
loop->nfds > 0);
920 loop->watchers[w->
fd] = NULL;
949 return 0 != (w->
pevents & events);
954 return (
unsigned) fd <
loop->nwatchers &&
loop->watchers[fd] != NULL;
961 if (getrusage(RUSAGE_SELF, &
usage))
970 #if !defined(__MVS__) && !defined(__HAIKU__)
992 #if defined(O_CLOEXEC)
1020 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
1023 r = dup3(oldfd, newfd, O_CLOEXEC);
1032 r = dup2(oldfd, newfd);
1090 #define CHECK_ENV_VAR(name) \
1092 buf = getenv(name); \
1094 goto return_buffer; \
1104 #undef CHECK_ENV_VAR
1107 #if defined(__ANDROID__)
1108 buf =
"/data/local/tmp";
1141 size_t homedir_size;
1145 #if defined(__ANDROID_API__) && __ANDROID_API__ < 21
1146 int (*getpwuid_r)(uid_t,
struct passwd*,
char*, size_t,
struct passwd**);
1148 getpwuid_r = dlsym(RTLD_DEFAULT,
"getpwuid_r");
1149 if (getpwuid_r == NULL)
1156 initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
1161 bufsize = (size_t) initsize;
1173 r = getpwuid_r(uid, &pw,
buf, bufsize, &
result);
1192 name_size = strlen(pw.pw_name) + 1;
1193 homedir_size = strlen(pw.pw_dir) + 1;
1194 shell_size = strlen(pw.pw_shell) + 1;
1214 pwd->
uid = pw.pw_uid;
1215 pwd->
gid = pw.pw_gid;
1246 return sys_errno <= 0 ? sys_errno : -sys_errno;
1261 if (*envitems == NULL)
1264 for (j = 0, cnt = 0; j <
i; j++) {
1283 envitem = &(*envitems)[cnt];
1294 for (
i = 0;
i < cnt;
i++) {
1295 envitem = &(*envitems)[cnt];
1347 if (unsetenv(
name) != 0)
1367 if (gethostname(
buf,
sizeof(
buf)) != 0)
1370 buf[
sizeof(
buf) - 1] =
'\0';
1409 r = getpriority(PRIO_PROCESS, (
int) pid);
1411 if (
r == -1 && errno != 0)
1423 if (setpriority(PRIO_PROCESS, (
int) pid,
priority) != 0)
1437 if (uname(&
buf) == -1) {
1452 if (
r >=
sizeof(
buffer->release)) {
1466 #if defined(_AIX) || defined(__PASE__)
1478 buffer->sysname[0] =
'\0';
1479 buffer->release[0] =
'\0';
1480 buffer->version[0] =
'\0';
1481 buffer->machine[0] =
'\0';
1487 struct sockaddr*
name,
1498 socklen = (socklen_t) *namelen;
1503 *namelen = (
int) socklen;
1513 if (gettimeofday(&time, NULL) != 0)
1526 timeout.tv_nsec = (msec % 1000) * 1000 * 1000;
1530 while (rc == -1 && errno == EINTR);
#define uv__is_closing(h)
FILE * uv__open_file(const char *path)
void uv__stream_close(uv_stream_t *handle)
int uv__dup2_cloexec(int oldfd, int newfd)
int uv_os_setenv(const char *name, const char *value)
int uv_backend_timeout(const uv_loop_t *loop)
void uv__run_prepare(uv_loop_t *loop)
void uv__run_check(uv_loop_t *loop)
int uv_os_getenv(const char *name, char *buffer, size_t *size)
void uv__udp_finish_close(uv_udp_t *handle)
int uv_os_homedir(char *buffer, size_t *size)
int uv__socket(int domain, int type, int protocol)
int uv_chdir(const char *dir)
#define CHECK_ENV_VAR(name)
void * uv__malloc(size_t size)
int uv__close_nocheckstdio(int fd)
void uv__tcp_close(uv_tcp_t *handle)
void uv__poll_close(uv_poll_t *handle)
int uv_os_gethostname(char *buffer, size_t *size)
#define UV_MAXHOSTNAMESIZE
static void uv__finish_close(uv_handle_t *handle)
uint64_t uv__hrtime(uv_clocktype_t type)
int uv_is_closing(const uv_handle_t *handle)
int uv__open_cloexec(const char *path, int flags)
void uv_os_free_passwd(uv_passwd_t *pwd)
int nanosleep(const struct timespec *req, struct timespec *rem)
int uv_os_get_passwd(uv_passwd_t *pwd)
int uv_os_environ(uv_env_item_t **envitems, int *count)
int uv__cloexec_fcntl(int fd, int set)
#define uv__has_active_handles(loop)
int uv_run(uv_loop_t *loop, uv_run_mode mode)
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
#define QUEUE_DATA(ptr, type, field)
uv_pid_t uv_os_getpid(void)
void uv_sleep(unsigned int msec)
#define uv__handle_unref(h)
void uv__fs_event_close(uv_fs_event_t *handle)
int uv_os_tmpdir(char *buffer, size_t *size)
int uv_os_uname(uv_utsname_t *buffer)
void uv__run_idle(uv_loop_t *loop)
void uv__timer_close(uv_timer_t *handle)
uv_pid_t uv_os_getppid(void)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void uv__async_close(uv_async_t *handle)
static unsigned int next_power_of_two(unsigned int val)
static void maybe_resize(uv_loop_t *loop, unsigned int len)
void uv__signal_close(uv_signal_t *handle)
int uv__fd_exists(uv_loop_t *loop, int fd)
int uv__io_active(const uv__io_t *w, unsigned int events)
char * uv__strdup(const char *s)
void uv_disable_stdio_inheritance(void)
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
void uv__make_close_pending(uv_handle_t *handle)
int uv__close_nocancel(int fd)
int uv__getsockpeername(const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
Poll< absl::StatusOr< std::tuple< T... > > > fail()
unsigned __int64 uint64_t
void uv__io_poll(uv_loop_t *loop, int timeout)
int uv_translate_sys_error(int sys_errno)
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
void uv__pipe_close(uv_pipe_t *handle)
void * uv__calloc(size_t count, size_t size)
static void uv__run_closing_handles(uv_loop_t *loop)
int epoll_file_close(int fd)
int uv_cwd(char *buffer, size_t *size)
int uv__next_timeout(const uv_loop_t *loop)
int uv__getpwuid_r(uv_passwd_t *pwd)
static void close_cb(uv_handle_t *handle)
ssize_t uv__recvmsg(int fd, struct msghdr *msg, int flags)
static int uv__run_pending(uv_loop_t *loop)
void * uv__reallocf(void *ptr, size_t size)
int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
int uv_is_active(const uv_handle_t *handle)
#define uv__has_active_reqs(loop)
int uv_gettimeofday(uv_timeval64_t *tv)
int uv__nonblock_fcntl(int fd, int set)
int uv__accept(int sockfd)
int uv_backend_fd(const uv_loop_t *loop)
ssize_t uv__strscpy(char *d, const char *s, size_t n)
void uv__io_feed(uv_loop_t *loop, uv__io_t *w)
int uv_loop_alive(const uv_loop_t *loop)
void uv__stream_destroy(uv_stream_t *stream)
void(* uv__io_cb)(struct uv_loop_s *loop, struct uv__io_s *w, unsigned int events)
int(* uv__peersockfunc)(int, struct sockaddr *, socklen_t *)
int uv_os_getpriority(uv_pid_t pid, int *priority)
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
#define uv__stream_fd(handle)
int uv__nonblock_ioctl(int fd, int set)
#define SAVE_ERRNO(block)
void uv__idle_close(uv_idle_t *handle)
uv_os_fd_t uv_get_osfhandle(int fd)
int uv__socket_sockopt(uv_handle_t *handle, int optname, int *value)
void uv__fs_poll_close(uv_fs_poll_t *handle)
int uv_os_setpriority(uv_pid_t pid, int priority)
STATIC_ASSERT(sizeof(uv_buf_t)==sizeof(struct iovec))
void uv__check_close(uv_check_t *handle)
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
void uv__process_close(uv_process_t *handle)
static int uv__loop_alive(const uv_loop_t *loop)
void(* uv_close_cb)(uv_handle_t *handle)
void uv__prepare_close(uv_prepare_t *handle)
int uv_open_osfhandle(uv_os_fd_t os_fd)
void uv__udp_close(uv_udp_t *handle)
void uv_update_time(uv_loop_t *loop)
void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
int uv_getrusage(uv_rusage_t *rusage)
#define QUEUE_INSERT_TAIL(h, q)
int uv__cloexec_ioctl(int fd, int set)
void uv__run_timers(uv_loop_t *loop)
OPENSSL_EXPORT pem_password_cb * cb
int uv_os_unsetenv(const char *name)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:58:57