Rizin
unix-like reverse engineering framework and cli tools
internal.h File Reference
#include "uv-common.h"
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <poll.h>

Go to the source code of this file.

Classes

struct  uv__stream_queued_fds_s
 

Macros

#define UV__PATH_MAX   8192
 
#define ACCESS_ONCE(type, var)    (*(volatile type*) &(var))
 
#define ROUND_UP(a, b)    ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))
 
#define UNREACHABLE()
 
#define SAVE_ERRNO(block)
 
#define UV_UNUSED(declaration)   declaration
 
#define UV__POLLRDHUP   0x2000
 
#define UV__POLLPRI   0
 
#define uv__cloexec   uv__cloexec_fcntl
 
#define uv__nonblock   uv__nonblock_fcntl
 
#define uv__stream_fd(handle)   ((handle)->io_watcher.fd)
 
#define UV__F_NONBLOCK   1
 
#define HAVE_MMSG   0
 

Typedefs

typedef struct uv__stream_queued_fds_s uv__stream_queued_fds_t
 
typedef int(* uv__peersockfunc) (int, struct sockaddr *, socklen_t *)
 

Enumerations

enum  { UV_LOOP_BLOCK_SIGPROF = 1 }
 
enum  { UV__EXCLUDE_IFPHYS , UV__EXCLUDE_IFADDR }
 
enum  uv_clocktype_t { UV_CLOCK_PRECISE = 0 , UV_CLOCK_FAST = 1 }
 

Functions

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)
 
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)
 
int uv__io_fork (uv_loop_t *loop)
 
int uv__fd_exists (uv_loop_t *loop, int fd)
 
void uv__async_stop (uv_loop_t *loop)
 
int uv__async_fork (uv_loop_t *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)
 
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)
 
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)
 
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)
 
int uv_pipe_listen (uv_pipe_t *handle, int backlog, uv_connection_cb cb)
 
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)
 
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)
 
void uv__async_close (uv_async_t *handle)
 
void uv__check_close (uv_check_t *handle)
 
void uv__fs_event_close (uv_fs_event_t *handle)
 
void uv__idle_close (uv_idle_t *handle)
 
void uv__pipe_close (uv_pipe_t *handle)
 
void uv__poll_close (uv_poll_t *handle)
 
void uv__prepare_close (uv_prepare_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)
 
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)
 
int uv__make_pipe (int fds[2], int flags)
 
 UV_UNUSED (static void uv__update_time(uv_loop_t *loop))
 
 UV_UNUSED (static char *uv__basename_r(const char *path))
 
int uv__getsockpeername (const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
 

Macro Definition Documentation

◆ ACCESS_ONCE

#define ACCESS_ONCE (   type,
  var 
)     (*(volatile type*) &(var))

Definition at line 79 of file internal.h.

◆ HAVE_MMSG

#define HAVE_MMSG   0

Definition at line 340 of file internal.h.

◆ ROUND_UP

#define ROUND_UP (   a,
  b 
)     ((a) % (b) ? ((a) + (b)) - ((a) % (b)) : (a))

Definition at line 82 of file internal.h.

◆ SAVE_ERRNO

#define SAVE_ERRNO (   block)
Value:
do { \
int _saved_errno = errno; \
do { block; } while (0); \
errno = _saved_errno; \
} \
while (0)

Definition at line 92 of file internal.h.

◆ UNREACHABLE

#define UNREACHABLE ( )
Value:
do { \
assert(0 && "unreachable code"); \
abort(); \
} \
while (0)

Definition at line 85 of file internal.h.

◆ uv__cloexec

#define uv__cloexec   uv__cloexec_fcntl

Definition at line 169 of file internal.h.

◆ UV__F_NONBLOCK

#define UV__F_NONBLOCK   1

Definition at line 288 of file internal.h.

◆ uv__nonblock

#define uv__nonblock   uv__nonblock_fcntl

Definition at line 170 of file internal.h.

◆ UV__PATH_MAX

#define UV__PATH_MAX   8192

Definition at line 68 of file internal.h.

◆ UV__POLLPRI

#define UV__POLLPRI   0

Definition at line 122 of file internal.h.

◆ UV__POLLRDHUP

#define UV__POLLRDHUP   0x2000

Definition at line 116 of file internal.h.

◆ uv__stream_fd

#define uv__stream_fd (   handle)    ((handle)->io_watcher.fd)

Definition at line 282 of file internal.h.

◆ UV_UNUSED

#define UV_UNUSED (   declaration )    declaration

Definition at line 109 of file internal.h.

Typedef Documentation

◆ uv__peersockfunc

typedef int(* uv__peersockfunc) (int, struct sockaddr *, socklen_t *)

Definition at line 321 of file internal.h.

◆ uv__stream_queued_fds_t

Definition at line 1 of file internal.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
UV_LOOP_BLOCK_SIGPROF 

Definition at line 136 of file internal.h.

136  {
138 };
@ UV_LOOP_BLOCK_SIGPROF
Definition: internal.h:137

◆ anonymous enum

anonymous enum
Enumerator
UV__EXCLUDE_IFPHYS 
UV__EXCLUDE_IFADDR 

Definition at line 141 of file internal.h.

141  {
144 };
@ UV__EXCLUDE_IFPHYS
Definition: internal.h:142
@ UV__EXCLUDE_IFADDR
Definition: internal.h:143

◆ uv_clocktype_t

Enumerator
UV_CLOCK_PRECISE 
UV_CLOCK_FAST 

Definition at line 146 of file internal.h.

146  {
147  UV_CLOCK_PRECISE = 0, /* Use the highest resolution clock available. */
148  UV_CLOCK_FAST = 1 /* Use the fastest clock with <= 1ms granularity. */
uv_clocktype_t
Definition: internal.h:146
@ UV_CLOCK_FAST
Definition: internal.h:148
@ UV_CLOCK_PRECISE
Definition: internal.h:147

Function Documentation

◆ uv__accept()

int uv__accept ( int  sockfd)

Definition at line 489 of file core.c.

489  {
490  int peerfd;
491  int err;
492 
493  (void) &err;
494  assert(sockfd >= 0);
495 
496  do
497 #ifdef uv__accept4
498  peerfd = uv__accept4(sockfd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
499 #else
500  peerfd = accept(sockfd, NULL, NULL);
501 #endif
502  while (peerfd == -1 && errno == EINTR);
503 
504  if (peerfd == -1)
505  return UV__ERR(errno);
506 
507 #ifndef uv__accept4
508  err = uv__cloexec(peerfd, 1);
509  if (err == 0)
510  err = uv__nonblock(peerfd, 1);
511 
512  if (err != 0) {
513  uv__close(peerfd);
514  return err;
515  }
516 #endif
517 
518  return peerfd;
519 }
static bool err
Definition: armass.c:435
#define NULL
Definition: cris-opc.c:27
#define UV__ERR(x)
Definition: errno.h:29
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset void static length char static len const struct iovec static count unsigned long static filedes static sched_yield static flags static oldfd static pause unsigned static seconds static protocol accept
Definition: sflib.h:75
assert(limit<=UINT32_MAX/2)
static sockfd
Definition: sfsocketcall.h:114
#define EINTR
Definition: sftypes.h:114
int uv__close(int fd)
Definition: core.c:569
#define uv__cloexec
Definition: internal.h:169
#define uv__nonblock
Definition: internal.h:170

References accept, assert(), EINTR, err, NULL, sockfd, uv__cloexec, uv__close(), UV__ERR, and uv__nonblock.

Referenced by uv__emfile_trick(), and uv__server_io().

◆ uv__async_close()

void uv__async_close ( uv_async_t handle)

Definition at line 115 of file async.c.

115  {
117  QUEUE_REMOVE(&handle->queue);
119 }
static mcore_handle handle
Definition: asm_mcore.c:8
#define QUEUE_REMOVE(q)
Definition: queue.h:101
static int uv__async_spin(uv_async_t *handle)
Definition: async.c:84
#define uv__handle_stop(h)
Definition: uv-common.h:266

References handle, QUEUE_REMOVE, uv__async_spin(), and uv__handle_stop.

Referenced by uv_close().

◆ uv__async_fork()

int uv__async_fork ( uv_loop_t loop)

Definition at line 230 of file async.c.

230  {
231  if (loop->async_io_watcher.fd == -1) /* never started */
232  return 0;
233 
235 
236  return uv__async_start(loop);
237 }
uv_loop_t * loop
Definition: main.c:7
void uv__async_stop(uv_loop_t *loop)
Definition: async.c:240
static int uv__async_start(uv_loop_t *loop)
Definition: async.c:202

References loop, uv__async_start(), and uv__async_stop().

Referenced by uv_loop_fork().

◆ uv__async_stop()

void uv__async_stop ( uv_loop_t loop)

Definition at line 240 of file async.c.

240  {
241  if (loop->async_io_watcher.fd == -1)
242  return;
243 
244  if (loop->async_wfd != -1) {
245  if (loop->async_wfd != loop->async_io_watcher.fd)
246  uv__close(loop->async_wfd);
247  loop->async_wfd = -1;
248  }
249 
250  uv__io_stop(loop, &loop->async_io_watcher, POLLIN);
251  uv__close(loop->async_io_watcher.fd);
252  loop->async_io_watcher.fd = -1;
253 }
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:910

References loop, uv__close(), and uv__io_stop().

Referenced by uv__async_fork(), and uv__loop_close().

◆ uv__check_close()

void uv__check_close ( uv_check_t handle)

Referenced by uv_close().

◆ uv__cloexec_fcntl()

int uv__cloexec_fcntl ( int  fd,
int  set 
)

Definition at line 639 of file core.c.

639  {
640  int flags;
641  int r;
642 
643  do
644  r = fcntl(fd, F_GETFD);
645  while (r == -1 && errno == EINTR);
646 
647  if (r == -1)
648  return UV__ERR(errno);
649 
650  /* Bail out now if already set/clear. */
651  if (!!(r & FD_CLOEXEC) == !!set)
652  return 0;
653 
654  if (set)
655  flags = r | FD_CLOEXEC;
656  else
657  flags = r & ~FD_CLOEXEC;
658 
659  do
660  r = fcntl(fd, F_SETFD, flags);
661  while (r == -1 && errno == EINTR);
662 
663  if (r)
664  return UV__ERR(errno);
665 
666  return 0;
667 }
#define r
Definition: crypto_rc6.c:12
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags fcntl
Definition: sflib.h:79
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define FD_CLOEXEC
Definition: sftypes.h:522
#define F_GETFD
Definition: sftypes.h:504
#define F_SETFD
Definition: sftypes.h:505
static const z80_opcode fd[]
Definition: z80_tab.h:997

References EINTR, F_GETFD, F_SETFD, fcntl, fd, FD_CLOEXEC, flags, r, and UV__ERR.

Referenced by uv__process_child_init().

◆ uv__cloexec_ioctl()

int uv__cloexec_ioctl ( int  fd,
int  set 
)

Definition at line 593 of file core.c.

593  {
594  int r;
595 
596  do
597  r = ioctl(fd, set ? FIOCLEX : FIONCLEX);
598  while (r == -1 && errno == EINTR);
599 
600  if (r)
601  return UV__ERR(errno);
602 
603  return 0;
604 }
static static sync static getppid static getegid const char static filename ioctl
Definition: sflib.h:62
#define FIOCLEX
Definition: sftypes.h:749
#define FIONCLEX
Definition: sftypes.h:748

References EINTR, fd, FIOCLEX, FIONCLEX, ioctl, r, and UV__ERR.

◆ uv__close()

◆ uv__close_nocancel()

int uv__close_nocancel ( int  fd)

Definition at line 530 of file core.c.

530  {
531 #if defined(__APPLE__)
532 #pragma GCC diagnostic push
533 #pragma GCC diagnostic ignored "-Wdollar-in-identifier-extension"
534 #if defined(__LP64__) || TARGET_OS_IPHONE
535  extern int close$NOCANCEL(int);
536  return close$NOCANCEL(fd);
537 #else
538  extern int close$NOCANCEL$UNIX2003(int);
539  return close$NOCANCEL$UNIX2003(fd);
540 #endif
541 #pragma GCC diagnostic pop
542 #elif defined(__linux__)
543  return syscall(SYS_close, fd);
544 #else
545  return close(fd);
546 #endif
547 }
static static fork const void static count close
Definition: sflib.h:33
const char * syscall
Definition: internal.h:270

References close, fd, and syscall.

Referenced by uv__close_nocheckstdio(), and uv__fs_close().

◆ uv__close_nocheckstdio()

int uv__close_nocheckstdio ( int  fd)

Definition at line 550 of file core.c.

550  {
551  int saved_errno;
552  int rc;
553 
554  assert(fd > -1); /* Catch uninitialized io_watcher.fd bugs. */
555 
556  saved_errno = errno;
557  rc = uv__close_nocancel(fd);
558  if (rc == -1) {
559  rc = UV__ERR(errno);
560  if (rc == UV_EINTR || rc == UV__ERR(EINPROGRESS))
561  rc = 0; /* The close is in progress, not an error. */
562  errno = saved_errno;
563  }
564 
565  return rc;
566 }
#define EINPROGRESS
Definition: sftypes.h:175
int uv__close_nocancel(int fd)
Definition: core.c:530

References assert(), EINPROGRESS, fd, uv__close_nocancel(), and UV__ERR.

Referenced by uv__close(), uv__fs_copyfile(), uv__slurp(), uv_fs_event_start(), and uv_spawn().

◆ uv__dup2_cloexec()

int uv__dup2_cloexec ( int  oldfd,
int  newfd 
)

Definition at line 1031 of file core.c.

1031  {
1032 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__)
1033  int r;
1034 
1035  r = dup3(oldfd, newfd, O_CLOEXEC);
1036  if (r == -1)
1037  return UV__ERR(errno);
1038 
1039  return r;
1040 #else
1041  int err;
1042  int r;
1043 
1044  r = dup2(oldfd, newfd); /* Never retry. */
1045  if (r == -1)
1046  return UV__ERR(errno);
1047 
1048  err = uv__cloexec(newfd, 1);
1049  if (err != 0) {
1050  uv__close(newfd);
1051  return err;
1052  }
1053 
1054  return r;
1055 #endif
1056 }
#define O_CLOEXEC
Definition: compat.h:80
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
Definition: sflib.h:94
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path oldfd
Definition: sflib.h:94

References dup2, err, O_CLOEXEC, oldfd, r, uv__cloexec, uv__close(), and UV__ERR.

Referenced by uv_tty_init().

◆ uv__fd_exists()

int uv__fd_exists ( uv_loop_t loop,
int  fd 
)

Definition at line 965 of file core.c.

965  {
966  return (unsigned) fd < loop->nwatchers && loop->watchers[fd] != NULL;
967 }

References fd, loop, and NULL.

Referenced by uv_pipe_open(), uv_poll_init(), uv_tcp_open(), and uv_udp_open().

◆ uv__fs_event_close()

void uv__fs_event_close ( uv_fs_event_t handle)

Definition at line 863 of file aix.c.

863  {
864 #ifdef HAVE_SYS_AHAFS_EVPRODS_H
866 #else
867  UNREACHABLE();
868 #endif
869 }
int uv_fs_event_stop(uv_fs_event_t *handle)
Definition: aix.c:838
#define UNREACHABLE()
Definition: internal.h:85

References handle, UNREACHABLE, and uv_fs_event_stop().

Referenced by uv_close().

◆ uv__getiovmax()

int uv__getiovmax ( void  )

Definition at line 215 of file core.c.

215  {
216 #if defined(IOV_MAX)
217  return IOV_MAX;
218 #elif defined(_SC_IOV_MAX)
219  static int iovmax_cached = -1;
220  int iovmax;
221 
222  iovmax = uv__load_relaxed(&iovmax_cached);
223  if (iovmax != -1)
224  return iovmax;
225 
226  /* On some embedded devices (arm-linux-uclibc based ip camera),
227  * sysconf(_SC_IOV_MAX) can not get the correct value. The return
228  * value is -1 and the errno is EINPROGRESS. Degrade the value to 1.
229  */
230  iovmax = sysconf(_SC_IOV_MAX);
231  if (iovmax == -1)
232  iovmax = 1;
233 
234  uv__store_relaxed(&iovmax_cached, iovmax);
235 
236  return iovmax;
237 #else
238  return 1024;
239 #endif
240 }
#define uv__load_relaxed(p)
Definition: uv-common.h:67
#define uv__store_relaxed(p, v)
Definition: uv-common.h:68

References uv__load_relaxed, and uv__store_relaxed.

Referenced by uv__fs_read(), uv__fs_write_all(), and uv__write().

◆ uv__getpwuid_r()

int uv__getpwuid_r ( uv_passwd_t pwd)

Definition at line 1146 of file core.c.

1146  {
1147  struct passwd pw;
1148  struct passwd* result;
1149  char* buf;
1150  uid_t uid;
1151  size_t bufsize;
1152  size_t name_size;
1153  size_t homedir_size;
1154  size_t shell_size;
1155  long initsize;
1156  int r;
1157 
1158  if (pwd == NULL)
1159  return UV_EINVAL;
1160 
1161  initsize = sysconf(_SC_GETPW_R_SIZE_MAX);
1162 
1163  if (initsize <= 0)
1164  bufsize = 4096;
1165  else
1166  bufsize = (size_t) initsize;
1167 
1168  uid = geteuid();
1169  buf = NULL;
1170 
1171  for (;;) {
1172  uv__free(buf);
1173  buf = uv__malloc(bufsize);
1174 
1175  if (buf == NULL)
1176  return UV_ENOMEM;
1177 
1178  r = getpwuid_r(uid, &pw, buf, bufsize, &result);
1179 
1180  if (r != ERANGE)
1181  break;
1182 
1183  bufsize *= 2;
1184  }
1185 
1186  if (r != 0) {
1187  uv__free(buf);
1188  return -r;
1189  }
1190 
1191  if (result == NULL) {
1192  uv__free(buf);
1193  return UV_ENOENT;
1194  }
1195 
1196  /* Allocate memory for the username, shell, and home directory */
1197  name_size = strlen(pw.pw_name) + 1;
1198  homedir_size = strlen(pw.pw_dir) + 1;
1199  shell_size = strlen(pw.pw_shell) + 1;
1200  pwd->username = uv__malloc(name_size + homedir_size + shell_size);
1201 
1202  if (pwd->username == NULL) {
1203  uv__free(buf);
1204  return UV_ENOMEM;
1205  }
1206 
1207  /* Copy the username */
1208  memcpy(pwd->username, pw.pw_name, name_size);
1209 
1210  /* Copy the home directory */
1211  pwd->homedir = pwd->username + name_size;
1212  memcpy(pwd->homedir, pw.pw_dir, homedir_size);
1213 
1214  /* Copy the shell */
1215  pwd->shell = pwd->homedir + homedir_size;
1216  memcpy(pwd->shell, pw.pw_shell, shell_size);
1217 
1218  /* Copy the uid and gid */
1219  pwd->uid = pw.pw_uid;
1220  pwd->gid = pw.pw_gid;
1221 
1222  uv__free(buf);
1223 
1224  return 0;
1225 }
voidpf void * buf
Definition: ioapi.h:138
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int uid_t
Definition: sftypes.h:44
int size_t
Definition: sftypes.h:40
#define ERANGE
Definition: sftypes.h:144
char * username
Definition: uv.h:1111
char * homedir
Definition: uv.h:1115
long uid
Definition: uv.h:1112
long gid
Definition: uv.h:1113
char * shell
Definition: uv.h:1114
ut8 * buf
Definition: core.c:75
void * uv__malloc(size_t size)
Definition: uv-common.c:75
void uv__free(void *ptr)
Definition: uv-common.c:81

◆ uv__getsockpeername()

int uv__getsockpeername ( const uv_handle_t handle,
uv__peersockfunc  func,
struct sockaddr name,
int namelen 
)

Definition at line 1490 of file core.c.

1493  {
1494  socklen_t socklen;
1495  uv_os_fd_t fd;
1496  int r;
1497 
1498  r = uv_fileno(handle, &fd);
1499  if (r < 0)
1500  return r;
1501 
1502  /* sizeof(socklen_t) != sizeof(int) on some systems. */
1503  socklen = (socklen_t) *namelen;
1504 
1505  if (func(fd, name, &socklen))
1506  return UV__ERR(errno);
1507 
1508  *namelen = (int) socklen;
1509  return 0;
1510 }
static int
Definition: sfsocketcall.h:114
unsigned int socklen_t
Definition: sftypes.h:219
Definition: z80asm.h:102
int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
Definition: core.c:767
int uv_os_fd_t
Definition: unix.h:130

References fd, handle, int, r, UV__ERR, and uv_fileno().

Referenced by uv__pipe_getsockpeername(), uv_tcp_getpeername(), uv_tcp_getsockname(), uv_udp_getpeername(), and uv_udp_getsockname().

◆ uv__handle_type()

uv_handle_type uv__handle_type ( int  fd)

Definition at line 958 of file stream.c.

958  {
959  struct sockaddr_storage ss;
960  socklen_t sslen;
961  socklen_t len;
962  int type;
963 
964  memset(&ss, 0, sizeof(ss));
965  sslen = sizeof(ss);
966 
967  if (getsockname(fd, (struct sockaddr*)&ss, &sslen))
968  return UV_UNKNOWN_HANDLE;
969 
970  len = sizeof type;
971 
972  if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &len))
973  return UV_UNKNOWN_HANDLE;
974 
975  if (type == SOCK_STREAM) {
976 #if defined(_AIX) || defined(__DragonFly__)
977  /* on AIX/DragonFly the getsockname call returns an empty sa structure
978  * for sockets of type AF_UNIX. For all other types it will
979  * return a properly filled in structure.
980  */
981  if (sslen == 0)
982  return UV_NAMED_PIPE;
983 #endif
984  switch (ss.ss_family) {
985  case AF_UNIX:
986  return UV_NAMED_PIPE;
987  case AF_INET:
988  case AF_INET6:
989  return UV_TCP;
990  }
991  }
992 
993  if (type == SOCK_DGRAM &&
994  (ss.ss_family == AF_INET || ss.ss_family == AF_INET6))
995  return UV_UDP;
996 
997  return UV_UNKNOWN_HANDLE;
998 }
size_t len
Definition: 6502dis.c:15
return memset(p, 0, total)
int type
Definition: mipsasm.c:17
#define AF_UNIX
Definition: sftypes.h:285
@ SOCK_DGRAM
Definition: sftypes.h:227
@ SOCK_STREAM
Definition: sftypes.h:224
#define SO_TYPE
Definition: sftypes.h:431
#define SOL_SOCKET
Definition: sftypes.h:427
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
@ UV_UNKNOWN_HANDLE
Definition: uv.h:190

References AF_INET, AF_INET6, AF_UNIX, fd, len, memset(), SO_TYPE, SOCK_DGRAM, SOCK_STREAM, SOL_SOCKET, type, and UV_UNKNOWN_HANDLE.

Referenced by uv_pipe_pending_type().

◆ uv__hrtime()

uint64_t uv__hrtime ( uv_clocktype_t  type)

Definition at line 43 of file aix-common.c.

43  {
44  uint64_t G = 1000000000;
45  timebasestruct_t t;
46  read_wall_time(&t, TIMEBASE_SZ);
47  time_base_to_time(&t, TIMEBASE_SZ);
48  return (uint64_t) t.tb_high * G + t.tb_low;
49 }
unsigned long uint64_t
Definition: sftypes.h:28
#define G
Definition: zip_err_str.c:13

References CLOCK_MONOTONIC_COARSE, done, G, NANOSEC, once, time_func, timebase, TOD_RES, timespec::tv_nsec, timespec::tv_sec, type, uv__hrtime_init_once(), uv__load_relaxed, uv__store_relaxed, UV_CLOCK_FAST, and uv_once().

Referenced by uv_cond_timedwait(), uv_hrtime(), UV_UNUSED(), and uv_update_time().

◆ uv__idle_close()

void uv__idle_close ( uv_idle_t handle)

Referenced by uv_close().

◆ uv__io_active()

int uv__io_active ( const uv__io_t w,
unsigned int  events 
)

Definition at line 958 of file core.c.

958  {
959  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
960  assert(0 != events);
961  return 0 != (w->pevents & events);
962 }
#define w
Definition: crypto_rc6.c:13
#define UV__POLLRDHUP
Definition: internal.h:116
#define UV__POLLPRI
Definition: internal.h:122

References assert(), UV__POLLPRI, UV__POLLRDHUP, and w.

Referenced by uv__read(), uv__stream_close(), uv__stream_destroy(), uv__stream_eof(), uv__udp_finish_close(), uv__udp_recv_start(), uv__udp_run_completed(), uv__write(), uv_read_stop(), and uv_try_write().

◆ uv__io_check_fd()

int uv__io_check_fd ( uv_loop_t loop,
int  fd 
)

Definition at line 115 of file aix.c.

115  {
116  struct poll_ctl pc;
117 
118  pc.events = POLLIN;
119  pc.cmd = PS_MOD; /* Equivalent to PS_ADD if the fd is not in the pollset. */
120  pc.fd = fd;
121 
122  if (pollset_ctl(loop->backend_fd, &pc, 1))
123  return UV__ERR(errno);
124 
125  pc.cmd = PS_DELETE;
126  if (pollset_ctl(loop->backend_fd, &pc, 1))
127  abort();
128 
129  return 0;
130 }

References e, EAGAIN, EEXIST, EINTR, epoll_ctl(), EPOLL_CTL_ADD, EPOLL_CTL_DEL, fd, loop, memset(), NULL, p, pc, poll, and UV__ERR.

Referenced by uv_poll_init().

◆ uv__io_close()

void uv__io_close ( uv_loop_t loop,
uv__io_t w 
)

Definition at line 942 of file core.c.

942  {
943  uv__io_stop(loop, w, POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI);
944  QUEUE_REMOVE(&w->pending_queue);
945 
946  /* Remove stale events for this file descriptor */
947  if (w->fd != -1)
949 }
void uv__platform_invalidate_fd(uv_loop_t *loop, int fd)
Definition: aix.c:1280

References loop, QUEUE_REMOVE, uv__io_stop(), uv__platform_invalidate_fd(), UV__POLLPRI, UV__POLLRDHUP, and w.

Referenced by uv__stream_close(), uv__udp_close(), and uv_fs_event_stop().

◆ uv__io_feed()

void uv__io_feed ( uv_loop_t loop,
uv__io_t w 
)

Definition at line 952 of file core.c.

952  {
953  if (QUEUE_EMPTY(&w->pending_queue))
954  QUEUE_INSERT_TAIL(&loop->pending_queue, &w->pending_queue);
955 }
#define QUEUE_EMPTY(q)
Definition: queue.h:39
#define QUEUE_INSERT_TAIL(h, q)
Definition: queue.h:92

References loop, QUEUE_EMPTY, QUEUE_INSERT_TAIL, and w.

Referenced by uv__tcp_connect(), uv__udp_sendmsg(), uv__write_req_finish(), and uv_pipe_connect().

◆ uv__io_fork()

int uv__io_fork ( uv_loop_t loop)

Definition at line 108 of file aix.c.

108  {
110 
112 }
int uv__platform_loop_init(uv_loop_t *loop)
Definition: aix.c:81
void uv__platform_loop_delete(uv_loop_t *loop)
Definition: aix.c:95

References err, loop, NULL, uv__close(), uv__free(), uv__inotify_fork(), uv__io_stop(), uv__kqueue_init(), uv__platform_loop_delete(), uv__platform_loop_init(), and uv__store_relaxed.

Referenced by uv_loop_fork().

◆ uv__io_init()

void uv__io_init ( uv__io_t w,
uv__io_cb  cb,
int  fd 
)

Definition at line 865 of file core.c.

865  {
866  assert(cb != NULL);
867  assert(fd >= -1);
868  QUEUE_INIT(&w->pending_queue);
869  QUEUE_INIT(&w->watcher_queue);
870  w->cb = cb;
871  w->fd = fd;
872  w->events = 0;
873  w->pevents = 0;
874 
875 #if defined(UV_HAVE_KQUEUE)
876  w->rcount = 0;
877  w->wcount = 0;
878 #endif /* defined(UV_HAVE_KQUEUE) */
879 }
#define QUEUE_INIT(q)
Definition: queue.h:45
static const char * cb[]
Definition: z80_tab.h:176

References assert(), cb, fd, NULL, QUEUE_INIT, and w.

Referenced by init_inotify(), uv__async_start(), uv__signal_loop_once_init(), uv__stream_init(), uv__udp_init_ex(), uv_fs_event_start(), and uv_poll_init().

◆ uv__io_poll()

void uv__io_poll ( uv_loop_t loop,
int  timeout 
)

Definition at line 133 of file aix.c.

133  {
134  struct pollfd events[1024];
135  struct pollfd pqry;
136  struct pollfd* pe;
137  struct poll_ctl pc;
138  QUEUE* q;
139  uv__io_t* w;
140  uint64_t base;
141  uint64_t diff;
142  int have_signals;
143  int nevents;
144  int count;
145  int nfds;
146  int i;
147  int rc;
148  int add_failed;
149  int user_timeout;
150  int reset_timeout;
151 
152  if (loop->nfds == 0) {
153  assert(QUEUE_EMPTY(&loop->watcher_queue));
154  return;
155  }
156 
157  while (!QUEUE_EMPTY(&loop->watcher_queue)) {
158  q = QUEUE_HEAD(&loop->watcher_queue);
159  QUEUE_REMOVE(q);
160  QUEUE_INIT(q);
161 
162  w = QUEUE_DATA(q, uv__io_t, watcher_queue);
163  assert(w->pevents != 0);
164  assert(w->fd >= 0);
165  assert(w->fd < (int) loop->nwatchers);
166 
167  pc.events = w->pevents;
168  pc.fd = w->fd;
169 
170  add_failed = 0;
171  if (w->events == 0) {
172  pc.cmd = PS_ADD;
173  if (pollset_ctl(loop->backend_fd, &pc, 1)) {
174  if (errno != EINVAL) {
175  assert(0 && "Failed to add file descriptor (pc.fd) to pollset");
176  abort();
177  }
178  /* Check if the fd is already in the pollset */
179  pqry.fd = pc.fd;
180  rc = pollset_query(loop->backend_fd, &pqry);
181  switch (rc) {
182  case -1:
183  assert(0 && "Failed to query pollset for file descriptor");
184  abort();
185  case 0:
186  assert(0 && "Pollset does not contain file descriptor");
187  abort();
188  }
189  /* If we got here then the pollset already contained the file descriptor even though
190  * we didn't think it should. This probably shouldn't happen, but we can continue. */
191  add_failed = 1;
192  }
193  }
194  if (w->events != 0 || add_failed) {
195  /* Modify, potentially removing events -- need to delete then add.
196  * Could maybe mod if we knew for sure no events are removed, but
197  * content of w->events is handled above as not reliable (falls back)
198  * so may require a pollset_query() which would have to be pretty cheap
199  * compared to a PS_DELETE to be worth optimizing. Alternatively, could
200  * lazily remove events, squelching them in the mean time. */
201  pc.cmd = PS_DELETE;
202  if (pollset_ctl(loop->backend_fd, &pc, 1)) {
203  assert(0 && "Failed to delete file descriptor (pc.fd) from pollset");
204  abort();
205  }
206  pc.cmd = PS_ADD;
207  if (pollset_ctl(loop->backend_fd, &pc, 1)) {
208  assert(0 && "Failed to add file descriptor (pc.fd) to pollset");
209  abort();
210  }
211  }
212 
213  w->events = w->pevents;
214  }
215 
216  assert(timeout >= -1);
217  base = loop->time;
218  count = 48; /* Benchmarks suggest this gives the best throughput. */
219 
221  reset_timeout = 1;
222  user_timeout = timeout;
223  timeout = 0;
224  } else {
225  reset_timeout = 0;
226  }
227 
228  for (;;) {
229  /* Only need to set the provider_entry_time if timeout != 0. The function
230  * will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
231  */
232  if (timeout != 0)
234 
235  nfds = pollset_poll(loop->backend_fd,
236  events,
237  ARRAY_SIZE(events),
238  timeout);
239 
240  /* Update loop->time unconditionally. It's tempting to skip the update when
241  * timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
242  * operating system didn't reschedule our process while in the syscall.
243  */
244  SAVE_ERRNO(uv__update_time(loop));
245 
246  if (nfds == 0) {
247  if (reset_timeout != 0) {
248  timeout = user_timeout;
249  reset_timeout = 0;
250  if (timeout == -1)
251  continue;
252  if (timeout > 0)
253  goto update_timeout;
254  }
255 
256  assert(timeout != -1);
257  return;
258  }
259 
260  if (nfds == -1) {
261  if (errno != EINTR) {
262  abort();
263  }
264 
265  if (reset_timeout != 0) {
266  timeout = user_timeout;
267  reset_timeout = 0;
268  }
269 
270  if (timeout == -1)
271  continue;
272 
273  if (timeout == 0)
274  return;
275 
276  /* Interrupted by a signal. Update timeout and poll again. */
277  goto update_timeout;
278  }
279 
280  have_signals = 0;
281  nevents = 0;
282 
283  assert(loop->watchers != NULL);
284  loop->watchers[loop->nwatchers] = (void*) events;
285  loop->watchers[loop->nwatchers + 1] = (void*) (uintptr_t) nfds;
286 
287  for (i = 0; i < nfds; i++) {
288  pe = events + i;
289  pc.cmd = PS_DELETE;
290  pc.fd = pe->fd;
291 
292  /* Skip invalidated events, see uv__platform_invalidate_fd */
293  if (pc.fd == -1)
294  continue;
295 
296  assert(pc.fd >= 0);
297  assert((unsigned) pc.fd < loop->nwatchers);
298 
299  w = loop->watchers[pc.fd];
300 
301  if (w == NULL) {
302  /* File descriptor that we've stopped watching, disarm it.
303  *
304  * Ignore all errors because we may be racing with another thread
305  * when the file descriptor is closed.
306  */
307  pollset_ctl(loop->backend_fd, &pc, 1);
308  continue;
309  }
310 
311  /* Run signal watchers last. This also affects child process watchers
312  * because those are implemented in terms of signal watchers.
313  */
314  if (w == &loop->signal_io_watcher) {
315  have_signals = 1;
316  } else {
318  w->cb(loop, w, pe->revents);
319  }
320 
321  nevents++;
322  }
323 
324  if (reset_timeout != 0) {
325  timeout = user_timeout;
326  reset_timeout = 0;
327  }
328 
329  if (have_signals != 0) {
331  loop->signal_io_watcher.cb(loop, &loop->signal_io_watcher, POLLIN);
332  }
333 
334  loop->watchers[loop->nwatchers] = NULL;
335  loop->watchers[loop->nwatchers + 1] = NULL;
336 
337  if (have_signals != 0)
338  return; /* Event loop should cycle now so don't poll again. */
339 
340  if (nevents != 0) {
341  if (nfds == ARRAY_SIZE(events) && --count != 0) {
342  /* Poll for more events but don't block this time. */
343  timeout = 0;
344  continue;
345  }
346  return;
347  }
348 
349  if (timeout == 0)
350  return;
351 
352  if (timeout == -1)
353  continue;
354 
355 update_timeout:
356  assert(timeout > 0);
357 
358  diff = loop->time - base;
359  if (diff >= (uint64_t) timeout)
360  return;
361 
362  timeout -= diff;
363  }
364 }
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count static fd const void static len static munlockall struct sched_param static p static sched_yield static policy const struct timespec struct timespec static rem uid_t uid_t uid_t static suid struct pollfd unsigned nfds
Definition: sflib.h:196
#define QUEUE_DATA(ptr, type, field)
Definition: queue.h:30
#define QUEUE_HEAD(q)
Definition: queue.h:42
void * QUEUE[2]
Definition: queue.h:21
#define EINVAL
Definition: sftypes.h:132
_W64 unsigned int uintptr_t
Definition: sftypes.h:75
Definition: unix.h:96
uv_timer_t timeout
Definition: main.c:9
void uv__metrics_update_idle_time(uv_loop_t *loop)
Definition: uv-common.c:872
void uv__metrics_set_provider_entry_time(uv_loop_t *loop)
Definition: uv-common.c:899
#define uv__get_internal_fields(loop)
Definition: uv-common.h:336
@ UV_METRICS_IDLE_TIME
Definition: uv.h:251

References ARRAY_SIZE, assert(), container_of, count, e, EBADF, EEXIST, EINTR, EINVAL, ENOENT, epoll_ctl(), EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD, epoll_wait(), err, EV_OOBAND, epoll_event::events, fd, epoll_event::fd, filter(), flags, i, epoll_event::is_msg, loop, memset(), nfds, NULL, op, os390_message_queue_handler(), pc, poll, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_INIT, QUEUE_INSERT_TAIL, QUEUE_REMOVE, SAVE_ERRNO, timeout, timespec::tv_nsec, timespec::tv_sec, uv__fs_event(), uv__get_internal_fields, uv__load_relaxed, uv__metrics_set_provider_entry_time(), uv__metrics_update_idle_time(), uv__platform_invalidate_fd(), uv__pollfds_add(), uv__pollfds_del(), UV__POLLPRI, UV__POLLRDHUP, uv__store_relaxed, UV_LOOP_BLOCK_SIGPROF, UV_METRICS_IDLE_TIME, w, and x.

Referenced by uv_run().

◆ uv__io_start()

void uv__io_start ( uv_loop_t loop,
uv__io_t w,
unsigned int  events 
)

Definition at line 882 of file core.c.

882  {
883  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
884  assert(0 != events);
885  assert(w->fd >= 0);
886  assert(w->fd < INT_MAX);
887 
888  w->pevents |= events;
889  maybe_resize(loop, w->fd + 1);
890 
891 #if !defined(__sun)
892  /* The event ports backend needs to rearm all file descriptors on each and
893  * every tick of the event loop but the other backends allow us to
894  * short-circuit here if the event mask is unchanged.
895  */
896  if (w->events == w->pevents)
897  return;
898 #endif
899 
900  if (QUEUE_EMPTY(&w->watcher_queue))
901  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
902 
903  if (loop->watchers[w->fd] == NULL) {
904  loop->watchers[w->fd] = w;
905  loop->nfds++;
906  }
907 }
#define INT_MAX
Definition: cp-demangle.c:131
static void maybe_resize(uv_loop_t *loop, unsigned int len)
Definition: core.c:830

References assert(), INT_MAX, loop, maybe_resize(), NULL, QUEUE_EMPTY, QUEUE_INSERT_TAIL, UV__POLLPRI, UV__POLLRDHUP, and w.

Referenced by init_inotify(), uv__async_start(), uv__read(), uv__server_io(), uv__signal_loop_once_init(), uv__tcp_connect(), uv__udp_recv_start(), uv__udp_send(), uv__write(), uv_accept(), uv_fs_event_start(), uv_pipe_connect(), uv_pipe_listen(), uv_poll_start(), uv_read_start(), uv_shutdown(), uv_tcp_listen(), and uv_write2().

◆ uv__io_stop()

void uv__io_stop ( uv_loop_t loop,
uv__io_t w,
unsigned int  events 
)

Definition at line 910 of file core.c.

910  {
911  assert(0 == (events & ~(POLLIN | POLLOUT | UV__POLLRDHUP | UV__POLLPRI)));
912  assert(0 != events);
913 
914  if (w->fd == -1)
915  return;
916 
917  assert(w->fd >= 0);
918 
919  /* Happens when uv__io_stop() is called on a handle that was never started. */
920  if ((unsigned) w->fd >= loop->nwatchers)
921  return;
922 
923  w->pevents &= ~events;
924 
925  if (w->pevents == 0) {
926  QUEUE_REMOVE(&w->watcher_queue);
927  QUEUE_INIT(&w->watcher_queue);
928 
929  if (loop->watchers[w->fd] != NULL) {
930  assert(loop->watchers[w->fd] == w);
931  assert(loop->nfds > 0);
932  loop->watchers[w->fd] = NULL;
933  loop->nfds--;
934  w->events = 0;
935  }
936  }
937  else if (QUEUE_EMPTY(&w->watcher_queue))
938  QUEUE_INSERT_TAIL(&loop->watcher_queue, &w->watcher_queue);
939 }

References assert(), loop, NULL, QUEUE_EMPTY, QUEUE_INIT, QUEUE_INSERT_TAIL, QUEUE_REMOVE, UV__POLLPRI, UV__POLLRDHUP, and w.

Referenced by uv__async_stop(), uv__drain(), uv__io_close(), uv__io_fork(), uv__platform_loop_delete(), uv__poll_io(), uv__poll_stop(), uv__read(), uv__server_io(), uv__signal_loop_fork(), uv__stream_connect(), uv__stream_eof(), uv__udp_run_completed(), uv__write(), uv_read_stop(), and uv_try_write().

◆ uv__kqueue_init()

int uv__kqueue_init ( uv_loop_t loop)

Definition at line 51 of file kqueue.c.

51  {
52  loop->backend_fd = kqueue();
53  if (loop->backend_fd == -1)
54  return UV__ERR(errno);
55 
56  uv__cloexec(loop->backend_fd, 1);
57 
58  return 0;
59 }

References loop, uv__cloexec, and UV__ERR.

Referenced by uv__io_fork(), and uv__platform_loop_init().

◆ uv__make_close_pending()

void uv__make_close_pending ( uv_handle_t handle)

Definition at line 208 of file core.c.

208  {
209  assert(handle->flags & UV_HANDLE_CLOSING);
210  assert(!(handle->flags & UV_HANDLE_CLOSED));
211  handle->next_closing = handle->loop->closing_handles;
212  handle->loop->closing_handles = handle;
213 }
@ UV_HANDLE_CLOSING
Definition: uv-common.h:74
@ UV_HANDLE_CLOSED
Definition: uv-common.h:75

References assert(), handle, UV_HANDLE_CLOSED, and UV_HANDLE_CLOSING.

Referenced by timer_close_cb(), uv__finish_close(), uv__fs_poll_close(), and uv_close().

◆ uv__make_pipe()

int uv__make_pipe ( int  fds[2],
int  flags 
)

Definition at line 142 of file process.c.

142  {
143 #if defined(__FreeBSD__) || defined(__linux__)
144  if (pipe2(fds, flags | O_CLOEXEC))
145  return UV__ERR(errno);
146 
147  return 0;
148 #else
149  if (pipe(fds))
150  return UV__ERR(errno);
151 
152  if (uv__cloexec(fds[0], 1))
153  goto fail;
154 
155  if (uv__cloexec(fds[1], 1))
156  goto fail;
157 
158  if (flags & UV__F_NONBLOCK) {
159  if (uv__nonblock(fds[0], 1))
160  goto fail;
161 
162  if (uv__nonblock(fds[1], 1))
163  goto fail;
164  }
165 
166  return 0;
167 
168 fail:
169  uv__close(fds[0]);
170  uv__close(fds[1]);
171  return UV__ERR(errno);
172 #endif
173 }
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname pipe
Definition: sflib.h:73
#define UV__F_NONBLOCK
Definition: internal.h:288
#define fail(test)
Definition: tests.h:29

References fail, flags, O_CLOEXEC, pipe, uv__cloexec, uv__close(), UV__ERR, UV__F_NONBLOCK, and uv__nonblock.

Referenced by uv__async_start(), uv__signal_global_reinit(), uv__signal_loop_once_init(), and uv_spawn().

◆ uv__nonblock_fcntl()

int uv__nonblock_fcntl ( int  fd,
int  set 
)

Definition at line 608 of file core.c.

608  {
609  int flags;
610  int r;
611 
612  do
613  r = fcntl(fd, F_GETFL);
614  while (r == -1 && errno == EINTR);
615 
616  if (r == -1)
617  return UV__ERR(errno);
618 
619  /* Bail out now if already set/clear. */
620  if (!!(r & O_NONBLOCK) == !!set)
621  return 0;
622 
623  if (set)
624  flags = r | O_NONBLOCK;
625  else
626  flags = r & ~O_NONBLOCK;
627 
628  do
629  r = fcntl(fd, F_SETFL, flags);
630  while (r == -1 && errno == EINTR);
631 
632  if (r)
633  return UV__ERR(errno);
634 
635  return 0;
636 }
#define F_GETFL
Definition: sftypes.h:506
#define O_NONBLOCK
Definition: sftypes.h:494
#define F_SETFL
Definition: sftypes.h:507

References EINTR, F_GETFL, F_SETFL, fcntl, fd, flags, O_NONBLOCK, r, and UV__ERR.

Referenced by uv__process_child_init(), and uv_poll_init().

◆ uv__nonblock_ioctl()

int uv__nonblock_ioctl ( int  fd,
int  set 
)

Definition at line 578 of file core.c.

578  {
579  int r;
580 
581  do
582  r = ioctl(fd, FIONBIO, &set);
583  while (r == -1 && errno == EINTR);
584 
585  if (r)
586  return UV__ERR(errno);
587 
588  return 0;
589 }
#define FIONBIO
Definition: sftypes.h:736

References EINTR, fd, FIONBIO, ioctl, r, and UV__ERR.

Referenced by uv_poll_init().

◆ uv__open_cloexec()

int uv__open_cloexec ( const char *  path,
int  flags 
)

Definition at line 1003 of file core.c.

1003  {
1004 #if defined(O_CLOEXEC)
1005  int fd;
1006 
1007  fd = open(path, flags | O_CLOEXEC);
1008  if (fd == -1)
1009  return UV__ERR(errno);
1010 
1011  return fd;
1012 #else /* O_CLOEXEC */
1013  int err;
1014  int fd;
1015 
1016  fd = open(path, flags);
1017  if (fd == -1)
1018  return UV__ERR(errno);
1019 
1020  err = uv__cloexec(fd, 1);
1021  if (err) {
1022  uv__close(fd);
1023  return err;
1024  }
1025 
1026  return fd;
1027 #endif /* O_CLOEXEC */
1028 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35

References err, fd, flags, O_CLOEXEC, path, uv__cloexec, uv__close(), and UV__ERR.

Referenced by uv__emfile_trick(), uv__open_file(), uv__random_readpath(), uv__slurp(), uv__stream_init(), uv_resident_set_memory(), and uv_tty_init().

◆ uv__open_file()

FILE* uv__open_file ( const char *  path)

Definition at line 473 of file core.c.

473  {
474  int fd;
475  FILE* fp;
476 
478  if (fd < 0)
479  return NULL;
480 
481  fp = fdopen(fd, "r");
482  if (fp == NULL)
483  uv__close(fd);
484 
485  return fp;
486 }
string FILE
Definition: benchmark.py:21
#define O_RDONLY
Definition: sftypes.h:486
int uv__open_cloexec(const char *path, int flags)
Definition: core.c:1003

References fd, benchmark::FILE, NULL, O_RDONLY, path, uv__close(), and uv__open_cloexec().

Referenced by read_cpufreq(), read_models(), and uv_cpu_info().

◆ uv__pipe_close()

void uv__pipe_close ( uv_pipe_t handle)

Definition at line 120 of file pipe.c.

120  {
121  if (handle->pipe_fname) {
122  /*
123  * Unlink the file system entity before closing the file descriptor.
124  * Doing it the other way around introduces a race where our process
125  * unlinks a socket with the same name that's just been created by
126  * another thread or process.
127  */
128  unlink(handle->pipe_fname);
129  uv__free((void*)handle->pipe_fname);
130  handle->pipe_fname = NULL;
131  }
132 
134 }
static static fork const void static count static fd const char static mode unlink
Definition: sflib.h:41
void uv__stream_close(uv_stream_t *handle)
Definition: stream.c:1633

References handle, NULL, unlink, uv__free(), and uv__stream_close().

Referenced by uv_close().

◆ uv__platform_invalidate_fd()

void uv__platform_invalidate_fd ( uv_loop_t loop,
int  fd 
)

Definition at line 1280 of file aix.c.

1280  {
1281  struct pollfd* events;
1282  uintptr_t i;
1283  uintptr_t nfds;
1284  struct poll_ctl pc;
1285 
1286  assert(loop->watchers != NULL);
1287  assert(fd >= 0);
1288 
1289  events = (struct pollfd*) loop->watchers[loop->nwatchers];
1290  nfds = (uintptr_t) loop->watchers[loop->nwatchers + 1];
1291 
1292  if (events != NULL)
1293  /* Invalidate events with same file descriptor */
1294  for (i = 0; i < nfds; i++)
1295  if ((int) events[i].fd == fd)
1296  events[i].fd = -1;
1297 
1298  /* Remove the file descriptor from the poll set */
1299  pc.events = 0;
1300  pc.cmd = PS_DELETE;
1301  pc.fd = fd;
1302  if(loop->backend_fd >= 0)
1303  pollset_ctl(loop->backend_fd, &pc, 1);
1304 }

References assert(), epoll_ctl(), EPOLL_CTL_DEL, epoll_event::events, fd, i, loop, memset(), nfds, NULL, pc, and uv__pollfds_del().

Referenced by uv__io_close(), uv__io_poll(), and uv__poll_stop().

◆ uv__platform_loop_delete()

void uv__platform_loop_delete ( uv_loop_t loop)

Definition at line 95 of file aix.c.

95  {
96  if (loop->fs_fd != -1) {
97  uv__close(loop->fs_fd);
98  loop->fs_fd = -1;
99  }
100 
101  if (loop->backend_fd != -1) {
102  pollset_destroy(loop->backend_fd);
103  loop->backend_fd = -1;
104  }
105 }

References epoll_queue_close(), loop, NULL, uv__close(), uv__free(), uv__fsevents_loop_delete(), and uv__io_stop().

Referenced by uv__io_fork(), uv__loop_close(), and uv_loop_init().

◆ uv__platform_loop_init()

int uv__platform_loop_init ( uv_loop_t loop)

Definition at line 81 of file aix.c.

81  {
82  loop->fs_fd = -1;
83 
84  /* Passing maxfd of -1 should mean the limit is determined
85  * by the user's ulimit or the global limit as per the doc */
86  loop->backend_fd = pollset_create(-1);
87 
88  if (loop->backend_fd == -1)
89  return -1;
90 
91  return 0;
92 }

References EINVAL, epoll_create1(), err, fd, loop, NULL, O_CLOEXEC, uv__cloexec, uv__close(), UV__ERR, and uv__kqueue_init().

Referenced by uv__io_fork(), and uv_loop_init().

◆ uv__poll_close()

void uv__poll_close ( uv_poll_t handle)

Definition at line 148 of file poll.c.

148  {
150 }
static void uv__poll_stop(uv_poll_t *handle)
Definition: poll.c:102

References handle, and uv__poll_stop().

Referenced by uv_close().

◆ uv__prepare_close()

void uv__prepare_close ( uv_prepare_t handle)

Referenced by uv_close().

◆ uv__process_close()

void uv__process_close ( uv_process_t handle)

Definition at line 590 of file process.c.

590  {
591  QUEUE_REMOVE(&handle->queue);
593  if (QUEUE_EMPTY(&handle->loop->process_handles))
594  uv_signal_stop(&handle->loop->child_watcher);
595 }
UV_EXTERN int uv_signal_stop(uv_signal_t *handle)
Definition: signal.c:513

References handle, QUEUE_EMPTY, QUEUE_REMOVE, uv__handle_stop, and uv_signal_stop().

Referenced by uv_close().

◆ uv__random_devurandom()

int uv__random_devurandom ( void *  buf,
size_t  buflen 
)

Definition at line 86 of file random-devurandom.c.

86  {
88 
89  if (status != 0)
90  return status;
91 
92  return uv__random_readpath("/dev/urandom", buf, buflen);
93 }
int uv__random_readpath(const char *path, void *buf, size_t buflen)
static int status
static uv_once_t once
static void uv__random_devurandom_init(void)
ut64 buflen
Definition: core.c:76
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419

References buflen, once, status, uv__random_devurandom_init(), uv__random_readpath(), and uv_once().

Referenced by uv__random().

◆ uv__random_getentropy()

int uv__random_getentropy ( void *  buf,
size_t  buflen 
)

Definition at line 39 of file random-getentropy.c.

39  {
40  size_t pos;
41  size_t stride;
42 
44 
45  if (uv__getentropy == NULL)
46  return UV_ENOSYS;
47 
48  /* getentropy() returns an error for requests > 256 bytes. */
49  for (pos = 0, stride = 256; pos + stride < buflen; pos += stride)
50  if (uv__getentropy((char *) buf + pos, stride))
51  return UV__ERR(errno);
52 
53  if (uv__getentropy((char *) buf + pos, buflen - pos))
54  return UV__ERR(errno);
55 
56  return 0;
57 }
static uv__getentropy_cb uv__getentropy
static void uv__random_getentropy_init(void)
static uv_once_t once
int pos
Definition: main.c:11

References buflen, NULL, once, pos, UV__ERR, uv__getentropy, uv__random_getentropy_init(), and uv_once().

Referenced by uv__random().

◆ uv__random_getrandom()

int uv__random_getrandom ( void *  buf,
size_t  buflen 
)

Definition at line 56 of file random-getrandom.c.

56  {
57  ssize_t n;
58  size_t pos;
59  int rc;
60 
62  if (rc != 0)
63  return rc;
64 
65  for (pos = 0; pos != buflen; pos += n) {
66  do {
67  n = buflen - pos;
68 
69  /* Most getrandom() implementations promise that reads <= 256 bytes
70  * will always succeed and won't be interrupted by signals.
71  * It's therefore useful to split it up in smaller reads because
72  * one big read may, in theory, continuously fail with EINTR.
73  */
74  if (n > 256)
75  n = 256;
76 
77  n = uv__getrandom((char *) buf + pos, n, 0);
78  } while (n == -1 && errno == EINTR);
79 
80  if (n == -1)
81  return UV__ERR(errno);
82 
83  if (n == 0)
84  return UV_EIO;
85  }
86 
87  return 0;
88 }
int n
Definition: mipsasm.c:19
static int uv__random_getrandom_init(void)
static uv__getrandom_cb uv__getrandom
int ssize_t
Definition: sftypes.h:39

References buflen, EINTR, n, pos, UV__ERR, uv__getrandom, and uv__random_getrandom_init().

Referenced by uv__random().

◆ uv__random_readpath()

int uv__random_readpath ( const char *  path,
void *  buf,
size_t  buflen 
)

Definition at line 32 of file random-devurandom.c.

32  {
33  struct stat s;
34  size_t pos;
35  ssize_t n;
36  int fd;
37 
39 
40  if (fd < 0)
41  return fd;
42 
43  if (fstat(fd, &s)) {
44  uv__close(fd);
45  return UV__ERR(errno);
46  }
47 
48  if (!S_ISCHR(s.st_mode)) {
49  uv__close(fd);
50  return UV_EIO;
51  }
52 
53  for (pos = 0; pos != buflen; pos += n) {
54  do
55  n = read(fd, (char*) buf + pos, buflen - pos);
56  while (n == -1 && errno == EINTR);
57 
58  if (n == -1) {
59  uv__close(fd);
60  return UV__ERR(errno);
61  }
62 
63  if (n == 0) {
64  uv__close(fd);
65  return UV_EIO;
66  }
67  }
68 
69  uv__close(fd);
70  return 0;
71 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset fstat
Definition: sflib.h:107
static RzSocket * s
Definition: rtr.c:28
Definition: sftypes.h:80
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References buflen, EINTR, fd, fstat, n, O_RDONLY, path, pos, read(), s, uv__close(), UV__ERR, and uv__open_cloexec().

Referenced by uv__random(), uv__random_devurandom(), and uv__random_devurandom_init().

◆ uv__random_sysctl()

int uv__random_sysctl ( void *  buf,
size_t  buflen 
)

Definition at line 238 of file netbsd.c.

238  {
239  static int name[] = {CTL_KERN, KERN_ARND};
240  size_t count, req;
241  unsigned char* p;
242 
243  p = buf;
244  while (len) {
245  req = len < 32 ? len : 32;
246  count = req;
247 
248  if (sysctl(name, ARRAY_SIZE(name), p, &count, NULL, 0) == -1)
249  return UV__ERR(errno);
250 
251  if (count != req)
252  return UV_EIO; /* Can't happen. */
253 
254  p += count;
255  len -= count;
256  }
257 
258  return 0;
259 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
Definition: sflib.h:128
void * p
Definition: libc.cpp:67

References args, ARRAY_SIZE, buflen, count, len, memcpy(), memset(), n, name, NULL, p, req, syscall, and UV__ERR.

Referenced by uv__random().

◆ uv__recvmsg()

ssize_t uv__recvmsg ( int  fd,
struct msghdr msg,
int  flags 
)

Definition at line 670 of file core.c.

670  {
671  struct cmsghdr* cmsg;
672  ssize_t rc;
673  int* pfd;
674  int* end;
675 #if defined(__linux__)
676  static int no_msg_cmsg_cloexec;
677  if (0 == uv__load_relaxed(&no_msg_cmsg_cloexec)) {
678  rc = recvmsg(fd, msg, flags | 0x40000000); /* MSG_CMSG_CLOEXEC */
679  if (rc != -1)
680  return rc;
681  if (errno != EINVAL)
682  return UV__ERR(errno);
683  rc = recvmsg(fd, msg, flags);
684  if (rc == -1)
685  return UV__ERR(errno);
686  uv__store_relaxed(&no_msg_cmsg_cloexec, 1);
687  } else {
688  rc = recvmsg(fd, msg, flags);
689  }
690 #else
691  rc = recvmsg(fd, msg, flags);
692 #endif
693  if (rc == -1)
694  return UV__ERR(errno);
695  if (msg->msg_controllen == 0)
696  return rc;
697  for (cmsg = CMSG_FIRSTHDR(msg); cmsg != NULL; cmsg = CMSG_NXTHDR(msg, cmsg))
698  if (cmsg->cmsg_type == SCM_RIGHTS)
699  for (pfd = (int*) CMSG_DATA(cmsg),
700  end = (int*) ((char*) cmsg + cmsg->cmsg_len);
701  pfd < end;
702  pfd += 1)
703  uv__cloexec(*pfd, 1);
704  return rc;
705 }
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119
@ SCM_RIGHTS
Definition: sftypes.h:383
#define CMSG_FIRSTHDR(mhdr)
Definition: sftypes.h:418
#define CMSG_NXTHDR(mhdr, cmsg)
Definition: sftypes.h:417
#define CMSG_DATA(cmsg)
Definition: sftypes.h:416
int cmsg_type
Definition: sftypes.h:412
size_t cmsg_len
Definition: sftypes.h:409

References CMSG_DATA, CMSG_FIRSTHDR, cmsghdr::cmsg_len, CMSG_NXTHDR, cmsghdr::cmsg_type, EINVAL, test_evm::end, fd, flags, msg, NULL, SCM_RIGHTS, uv__cloexec, UV__ERR, uv__load_relaxed, and uv__store_relaxed.

Referenced by uv__read().

◆ uv__run_check()

void uv__run_check ( uv_loop_t loop)

Referenced by uv_run().

◆ uv__run_idle()

void uv__run_idle ( uv_loop_t loop)

Referenced by uv_run().

◆ uv__run_prepare()

void uv__run_prepare ( uv_loop_t loop)

Referenced by uv_run().

◆ uv__search_path()

int uv__search_path ( const char *  prog,
char *  buf,
size_t buflen 
)

Definition at line 1540 of file core.c.

1540  {
1541  char abspath[UV__PATH_MAX];
1542  size_t abspath_size;
1543  char trypath[UV__PATH_MAX];
1544  char* cloned_path;
1545  char* path_env;
1546  char* token;
1547 
1548  if (buf == NULL || buflen == NULL || *buflen == 0)
1549  return UV_EINVAL;
1550 
1551  /*
1552  * Possibilities for prog:
1553  * i) an absolute path such as: /home/user/myprojects/nodejs/node
1554  * ii) a relative path such as: ./node or ../myprojects/nodejs/node
1555  * iii) a bare filename such as "node", after exporting PATH variable
1556  * to its location.
1557  */
1558 
1559  /* Case i) and ii) absolute or relative paths */
1560  if (strchr(prog, '/') != NULL) {
1561  if (realpath(prog, abspath) != abspath)
1562  return UV__ERR(errno);
1563 
1564  abspath_size = strlen(abspath);
1565 
1566  *buflen -= 1;
1567  if (*buflen > abspath_size)
1568  *buflen = abspath_size;
1569 
1570  memcpy(buf, abspath, *buflen);
1571  buf[*buflen] = '\0';
1572 
1573  return 0;
1574  }
1575 
1576  /* Case iii). Search PATH environment variable */
1577  cloned_path = NULL;
1578  token = NULL;
1579  path_env = getenv("PATH");
1580 
1581  if (path_env == NULL)
1582  return UV_EINVAL;
1583 
1584  cloned_path = uv__strdup(path_env);
1585  if (cloned_path == NULL)
1586  return UV_ENOMEM;
1587 
1588  token = strtok(cloned_path, ":");
1589  while (token != NULL) {
1590  snprintf(trypath, sizeof(trypath) - 1, "%s/%s", token, prog);
1591  if (realpath(trypath, abspath) == abspath) {
1592  /* Check the match is executable */
1593  if (access(abspath, X_OK) == 0) {
1594  abspath_size = strlen(abspath);
1595 
1596  *buflen -= 1;
1597  if (*buflen > abspath_size)
1598  *buflen = abspath_size;
1599 
1600  memcpy(buf, abspath, *buflen);
1601  buf[*buflen] = '\0';
1602 
1603  uv__free(cloned_path);
1604  return 0;
1605  }
1606  }
1607  token = strtok(NULL, ":");
1608  }
1609  uv__free(cloned_path);
1610 
1611  /* Out of tokens (path entries), and no match found */
1612  return UV_EINVAL;
1613 }
snprintf
Definition: kernel.h:364
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause access
Definition: sflib.h:64
char * getenv()
#define UV__PATH_MAX
Definition: internal.h:68
char * prog
Definition: untgz.c:125
char * uv__strdup(const char *s)
Definition: uv-common.c:55
#define X_OK
Definition: win.h:664

References access, buflen, getenv(), memcpy(), NULL, prog, snprintf, UV__ERR, uv__free(), UV__PATH_MAX, uv__strdup(), and X_OK.

Referenced by uv_exepath(), and uv_setup_args().

◆ uv__server_io()

void uv__server_io ( uv_loop_t loop,
uv__io_t w,
unsigned int  events 
)

Definition at line 528 of file stream.c.

528  {
530  int err;
531 
532  stream = container_of(w, uv_stream_t, io_watcher);
533  assert(events & POLLIN);
534  assert(stream->accepted_fd == -1);
535  assert(!(stream->flags & UV_HANDLE_CLOSING));
536 
537  uv__io_start(stream->loop, &stream->io_watcher, POLLIN);
538 
539  /* connection_cb can close the server socket while we're
540  * in the loop so check it on each iteration.
541  */
542  while (uv__stream_fd(stream) != -1) {
543  assert(stream->accepted_fd == -1);
544 
545 #if defined(UV_HAVE_KQUEUE)
546  if (w->rcount <= 0)
547  return;
548 #endif /* defined(UV_HAVE_KQUEUE) */
549 
551  if (err < 0) {
552  if (err == UV_EAGAIN || err == UV__ERR(EWOULDBLOCK))
553  return; /* Not an error. */
554 
555  if (err == UV_ECONNABORTED)
556  continue; /* Ignore. Nothing we can do about that. */
557 
558  if (err == UV_EMFILE || err == UV_ENFILE) {
560  if (err == UV_EAGAIN || err == UV__ERR(EWOULDBLOCK))
561  break;
562  }
563 
564  stream->connection_cb(stream, err);
565  continue;
566  }
567 
569  stream->accepted_fd = err;
570  stream->connection_cb(stream, 0);
571 
572  if (stream->accepted_fd != -1) {
573  /* The user hasn't yet accepted called uv_accept() */
574  uv__io_stop(loop, &stream->io_watcher, POLLIN);
575  return;
576  }
577 
578  if (stream->type == UV_TCP &&
579  (stream->flags & UV_HANDLE_TCP_SINGLE_ACCEPT)) {
580  /* Give other processes a chance to accept connections. */
581  struct timespec timeout = { 0, 1 };
583  }
584  }
585 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg nanosleep
Definition: sflib.h:128
voidpf stream
Definition: ioapi.h:138
#define container_of(ptr, type, member)
Definition: rz_types.h:650
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:882
int uv__accept(int sockfd)
Definition: core.c:489
#define uv__stream_fd(handle)
Definition: internal.h:282
static int uv__emfile_trick(uv_loop_t *loop, int accept_fd)
Definition: stream.c:497
#define UV_DEC_BACKLOG(w)
Definition: stream.c:524
@ UV_HANDLE_TCP_SINGLE_ACCEPT
Definition: uv-common.h:107

References assert(), container_of, err, loop, nanosleep, NULL, timeout, uv__accept(), uv__emfile_trick(), UV__ERR, uv__io_start(), uv__io_stop(), uv__stream_fd, UV_DEC_BACKLOG, UV_HANDLE_CLOSING, UV_HANDLE_TCP_SINGLE_ACCEPT, and w.

Referenced by uv_pipe_listen(), and uv_tcp_listen().

◆ uv__signal_close()

void uv__signal_close ( uv_signal_t handle)

Definition at line 335 of file signal.c.

335  {
337 }
static void uv__signal_stop(uv_signal_t *handle)
Definition: signal.c:520

References handle, and uv__signal_stop().

Referenced by uv_close().

◆ uv__signal_global_once_init()

void uv__signal_global_once_init ( void  )

Definition at line 111 of file signal.c.

111  {
112  uv_once(&uv__signal_global_init_guard, uv__signal_global_init);
113 }
static uv_once_t uv__signal_global_init_guard
Definition: signal.c:54

References uv__signal_global_init_guard, and uv_once().

Referenced by uv_loop_init().

◆ uv__signal_loop_cleanup()

void uv__signal_loop_cleanup ( uv_loop_t loop)

Definition at line 291 of file signal.c.

291  {
292  QUEUE* q;
293 
294  /* Stop all the signal watchers that are still attached to this loop. This
295  * ensures that the (shared) signal tree doesn't contain any invalid entries
296  * entries, and that signal handlers are removed when appropriate.
297  * It's safe to use QUEUE_FOREACH here because the handles and the handle
298  * queue are not modified by uv__signal_stop().
299  */
301  uv_handle_t* handle = QUEUE_DATA(q, uv_handle_t, handle_queue);
302 
303  if (handle->type == UV_SIGNAL)
305  }
306 
307  if (loop->signal_pipefd[0] != -1) {
308  uv__close(loop->signal_pipefd[0]);
309  loop->signal_pipefd[0] = -1;
310  }
311 
312  if (loop->signal_pipefd[1] != -1) {
313  uv__close(loop->signal_pipefd[1]);
314  loop->signal_pipefd[1] = -1;
315  }
316 }
#define QUEUE_FOREACH(q, h)
Definition: queue.h:36
void * handle_queue[2]
Definition: uv.h:1785

References handle, uv_loop_s::handle_queue, loop, QUEUE_DATA, QUEUE_FOREACH, uv__close(), and uv__signal_stop().

Referenced by uv__loop_close(), and uv_loop_init().

◆ uv__signal_loop_fork()

int uv__signal_loop_fork ( uv_loop_t loop)

Definition at line 281 of file signal.c.

281  {
282  uv__io_stop(loop, &loop->signal_io_watcher, POLLIN);
283  uv__close(loop->signal_pipefd[0]);
284  uv__close(loop->signal_pipefd[1]);
285  loop->signal_pipefd[0] = -1;
286  loop->signal_pipefd[1] = -1;
288 }
static int uv__signal_loop_once_init(uv_loop_t *loop)
Definition: signal.c:261

References loop, uv__close(), uv__io_stop(), and uv__signal_loop_once_init().

Referenced by uv_loop_fork().

◆ uv__socket()

int uv__socket ( int  domain,
int  type,
int  protocol 
)

Definition at line 436 of file core.c.

436  {
437  int sockfd;
438  int err;
439 
440 #if defined(SOCK_NONBLOCK) && defined(SOCK_CLOEXEC)
441  sockfd = socket(domain, type | SOCK_NONBLOCK | SOCK_CLOEXEC, protocol);
442  if (sockfd != -1)
443  return sockfd;
444 
445  if (errno != EINVAL)
446  return UV__ERR(errno);
447 #endif
448 
449  sockfd = socket(domain, type, protocol);
450  if (sockfd == -1)
451  return UV__ERR(errno);
452 
453  err = uv__nonblock(sockfd, 1);
454  if (err == 0)
455  err = uv__cloexec(sockfd, 1);
456 
457  if (err) {
458  uv__close(sockfd);
459  return err;
460  }
461 
462 #if defined(SO_NOSIGPIPE)
463  {
464  int on = 1;
465  setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, &on, sizeof(on));
466  }
467 #endif
468 
469  return sockfd;
470 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd domain
Definition: sflib.h:79
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd socket
Definition: sflib.h:79

References domain, EINVAL, err, socket, sockfd, SOL_SOCKET, type, uv__cloexec, uv__close(), UV__ERR, and uv__nonblock.

Referenced by new_socket(), uv__udp_bind(), uv__udp_init_ex(), uv_pipe_bind(), and uv_pipe_connect().

◆ uv__stream_close()

void uv__stream_close ( uv_stream_t handle)

Definition at line 1633 of file stream.c.

1633  {
1634  unsigned int i;
1635  uv__stream_queued_fds_t* queued_fds;
1636 
1637 #if defined(__APPLE__)
1638  /* Terminate select loop first */
1639  if (handle->select != NULL) {
1640  uv__stream_select_t* s;
1641 
1642  s = handle->select;
1643 
1644  uv_sem_post(&s->close_sem);
1645  uv_sem_post(&s->async_sem);
1647  uv_thread_join(&s->thread);
1648  uv_sem_destroy(&s->close_sem);
1649  uv_sem_destroy(&s->async_sem);
1650  uv__close(s->fake_fd);
1651  uv__close(s->int_fd);
1652  uv_close((uv_handle_t*) &s->async, uv__stream_osx_cb_close);
1653 
1654  handle->select = NULL;
1655  }
1656 #endif /* defined(__APPLE__) */
1657 
1658  uv__io_close(handle->loop, &handle->io_watcher);
1662 
1663  if (handle->io_watcher.fd != -1) {
1664  /* Don't close stdio file descriptors. Nothing good comes from it. */
1665  if (handle->io_watcher.fd > STDERR_FILENO)
1666  uv__close(handle->io_watcher.fd);
1667  handle->io_watcher.fd = -1;
1668  }
1669 
1670  if (handle->accepted_fd != -1) {
1671  uv__close(handle->accepted_fd);
1672  handle->accepted_fd = -1;
1673  }
1674 
1675  /* Close all queued fds */
1676  if (handle->queued_fds != NULL) {
1677  queued_fds = handle->queued_fds;
1678  for (i = 0; i < queued_fds->offset; i++)
1679  uv__close(queued_fds->fds[i]);
1680  uv__free(handle->queued_fds);
1681  handle->queued_fds = NULL;
1682  }
1683 
1684  assert(!uv__io_active(&handle->io_watcher, POLLIN | POLLOUT));
1685 }
unsigned int offset
Definition: internal.h:153
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
Definition: core.c:942
int uv__io_active(const uv__io_t *w, unsigned int events)
Definition: core.c:958
static void uv__stream_osx_interrupt_select(uv_stream_t *stream)
Definition: stream.c:123
int uv_read_stop(uv_stream_t *stream)
Definition: stream.c:1590
@ UV_HANDLE_WRITABLE
Definition: uv-common.h:93
@ UV_HANDLE_READABLE
Definition: uv-common.h:92
UV_EXTERN int uv_thread_join(uv_thread_t *tid)
Definition: thread.c:272
UV_EXTERN void uv_sem_destroy(uv_sem_t *sem)
Definition: thread.c:662
UV_EXTERN void uv_sem_post(uv_sem_t *sem)
Definition: thread.c:670
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: core.c:108

References assert(), uv__stream_queued_fds_s::fds, handle, i, NULL, uv__stream_queued_fds_s::offset, s, STDERR_FILENO, uv__close(), uv__free(), uv__handle_stop, uv__io_active(), uv__io_close(), uv__stream_osx_interrupt_select(), uv_close(), UV_HANDLE_READABLE, UV_HANDLE_WRITABLE, uv_read_stop(), uv_sem_destroy(), uv_sem_post(), and uv_thread_join().

Referenced by uv__pipe_close(), uv__process_close_stream(), uv__tcp_close(), and uv_close().

◆ uv__stream_destroy()

void uv__stream_destroy ( uv_stream_t stream)

Definition at line 458 of file stream.c.

458  {
459  assert(!uv__io_active(&stream->io_watcher, POLLIN | POLLOUT));
460  assert(stream->flags & UV_HANDLE_CLOSED);
461 
462  if (stream->connect_req) {
463  uv__req_unregister(stream->loop, stream->connect_req);
464  stream->connect_req->cb(stream->connect_req, UV_ECANCELED);
465  stream->connect_req = NULL;
466  }
467 
468  uv__stream_flush_write_queue(stream, UV_ECANCELED);
470 
471  if (stream->shutdown_req) {
472  /* The ECANCELED error code is a lie, the shutdown(2) syscall is a
473  * fait accompli at this point. Maybe we should revisit this in v0.11.
474  * A possible reason for leaving it unchanged is that it informs the
475  * callee that the handle has been destroyed.
476  */
477  uv__req_unregister(stream->loop, stream->shutdown_req);
478  stream->shutdown_req->cb(stream->shutdown_req, UV_ECANCELED);
479  stream->shutdown_req = NULL;
480  }
481 
482  assert(stream->write_queue_size == 0);
483 }
void uv__stream_flush_write_queue(uv_stream_t *stream, int error)
Definition: stream.c:443
static void uv__write_callbacks(uv_stream_t *stream)
Definition: stream.c:927
#define uv__req_unregister(loop, req)
Definition: uv-common.h:230

References assert(), NULL, uv__io_active(), uv__req_unregister, uv__stream_flush_write_queue(), uv__write_callbacks(), and UV_HANDLE_CLOSED.

Referenced by uv__finish_close().

◆ uv__stream_init()

void uv__stream_init ( uv_loop_t loop,
uv_stream_t stream,
uv_handle_type  type 
)

Definition at line 85 of file stream.c.

87  {
88  int err;
89 
91  stream->read_cb = NULL;
92  stream->alloc_cb = NULL;
93  stream->close_cb = NULL;
94  stream->connection_cb = NULL;
95  stream->connect_req = NULL;
96  stream->shutdown_req = NULL;
97  stream->accepted_fd = -1;
98  stream->queued_fds = NULL;
99  stream->delayed_error = 0;
100  QUEUE_INIT(&stream->write_queue);
101  QUEUE_INIT(&stream->write_completed_queue);
102  stream->write_queue_size = 0;
103 
104  if (loop->emfile_fd == -1) {
105  err = uv__open_cloexec("/dev/null", O_RDONLY);
106  if (err < 0)
107  /* In the rare case that "/dev/null" isn't mounted open "/"
108  * instead.
109  */
110  err = uv__open_cloexec("/", O_RDONLY);
111  if (err >= 0)
112  loop->emfile_fd = err;
113  }
114 
115 #if defined(__APPLE__)
116  stream->select = NULL;
117 #endif /* defined(__APPLE_) */
118 
119  uv__io_init(&stream->io_watcher, uv__stream_io, -1);
120 }
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
Definition: core.c:865
static void uv__stream_io(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: stream.c:1287
#define uv__handle_init(loop_, h, type_)
Definition: uv-common.h:301

References err, loop, NULL, O_RDONLY, QUEUE_INIT, type, uv__handle_init, uv__io_init(), uv__open_cloexec(), and uv__stream_io().

Referenced by uv_pipe_init(), uv_tcp_init_ex(), and uv_tty_init().

◆ uv__stream_open()

int uv__stream_open ( uv_stream_t stream,
int  fd,
int  flags 
)

Definition at line 406 of file stream.c.

406  {
407 #if defined(__APPLE__)
408  int enable;
409 #endif
410 
411  if (!(stream->io_watcher.fd == -1 || stream->io_watcher.fd == fd))
412  return UV_EBUSY;
413 
414  assert(fd >= 0);
415  stream->flags |= flags;
416 
417  if (stream->type == UV_TCP) {
418  if ((stream->flags & UV_HANDLE_TCP_NODELAY) && uv__tcp_nodelay(fd, 1))
419  return UV__ERR(errno);
420 
421  /* TODO Use delay the user passed in. */
422  if ((stream->flags & UV_HANDLE_TCP_KEEPALIVE) &&
423  uv__tcp_keepalive(fd, 1, 60)) {
424  return UV__ERR(errno);
425  }
426  }
427 
428 #if defined(__APPLE__)
429  enable = 1;
430  if (setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &enable, sizeof(enable)) &&
431  errno != ENOTSOCK &&
432  errno != EINVAL) {
433  return UV__ERR(errno);
434  }
435 #endif
436 
437  stream->io_watcher.fd = fd;
438 
439  return 0;
440 }
#define SO_OOBINLINE
Definition: sftypes.h:438
#define ENOTSOCK
Definition: sftypes.h:148
int uv__tcp_keepalive(int fd, int on, unsigned int delay)
Definition: tcp.c:380
int uv__tcp_nodelay(int fd, int on)
Definition: tcp.c:373
@ UV_HANDLE_TCP_KEEPALIVE
Definition: uv-common.h:106
@ UV_HANDLE_TCP_NODELAY
Definition: uv-common.h:105

References assert(), EINVAL, ENOTSOCK, fd, flags, SO_OOBINLINE, SOL_SOCKET, UV__ERR, uv__tcp_keepalive(), uv__tcp_nodelay(), UV_HANDLE_TCP_KEEPALIVE, and UV_HANDLE_TCP_NODELAY.

Referenced by new_socket(), uv__process_open_stream(), uv_accept(), uv_pipe_connect(), uv_pipe_open(), uv_tcp_open(), and uv_tty_init().

◆ uv__tcp_close()

void uv__tcp_close ( uv_tcp_t handle)

Definition at line 459 of file tcp.c.

459  {
461 }

References handle, and uv__stream_close().

Referenced by uv_close().

◆ uv__tcp_keepalive()

int uv__tcp_keepalive ( int  fd,
int  on,
unsigned int  delay 
)

Definition at line 380 of file tcp.c.

380  {
381  if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)))
382  return UV__ERR(errno);
383 
384 #ifdef TCP_KEEPIDLE
385  if (on) {
386  int intvl = 1; /* 1 second; same as default on Win32 */
387  int cnt = 10; /* 10 retries; same as hardcoded on Win32 */
388  if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &delay, sizeof(delay)))
389  return UV__ERR(errno);
390  if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &intvl, sizeof(intvl)))
391  return UV__ERR(errno);
392  if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &cnt, sizeof(cnt)))
393  return UV__ERR(errno);
394  }
395 #endif
396 
397  /* Solaris/SmartOS, if you don't support keep-alive,
398  * then don't advertise it in your system headers...
399  */
400  /* FIXME(bnoordhuis) That's possibly because sizeof(delay) should be 1. */
401 #if defined(TCP_KEEPALIVE) && !defined(__sun)
402  if (on && setsockopt(fd, IPPROTO_TCP, TCP_KEEPALIVE, &delay, sizeof(delay)))
403  return UV__ERR(errno);
404 #endif
405 
406  return 0;
407 }
#define SO_KEEPALIVE
Definition: sftypes.h:437
#define TCP_KEEPALIVE
Definition: winsock.h:42

References fd, SO_KEEPALIVE, SOL_SOCKET, TCP_KEEPALIVE, and UV__ERR.

Referenced by uv__stream_open(), uv_tcp_keepalive(), and uv_tcp_set_socket().

◆ uv__tcp_nodelay()

int uv__tcp_nodelay ( int  fd,
int  on 
)

Definition at line 373 of file tcp.c.

373  {
374  if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)))
375  return UV__ERR(errno);
376  return 0;
377 }

References fd, and UV__ERR.

Referenced by uv__stream_open(), uv_tcp_nodelay(), and uv_tcp_set_socket().

◆ uv__udp_close()

void uv__udp_close ( uv_udp_t handle)

Definition at line 90 of file udp.c.

90  {
91  uv__io_close(handle->loop, &handle->io_watcher);
93 
94  if (handle->io_watcher.fd != -1) {
95  uv__close(handle->io_watcher.fd);
96  handle->io_watcher.fd = -1;
97  }
98 }

References handle, uv__close(), uv__handle_stop, and uv__io_close().

Referenced by uv_close().

◆ uv__udp_finish_close()

void uv__udp_finish_close ( uv_udp_t handle)

Definition at line 101 of file udp.c.

101  {
103  QUEUE* q;
104 
105  assert(!uv__io_active(&handle->io_watcher, POLLIN | POLLOUT));
106  assert(handle->io_watcher.fd == -1);
107 
108  while (!QUEUE_EMPTY(&handle->write_queue)) {
109  q = QUEUE_HEAD(&handle->write_queue);
110  QUEUE_REMOVE(q);
111 
113  req->status = UV_ECANCELED;
114  QUEUE_INSERT_TAIL(&handle->write_completed_queue, &req->queue);
115  }
116 
118 
119  assert(handle->send_queue_size == 0);
120  assert(handle->send_queue_count == 0);
121 
122  /* Now tear down the handle. */
123  handle->recv_cb = NULL;
124  handle->alloc_cb = NULL;
125  /* but _do not_ touch close_cb */
126 }
static void uv__udp_run_completed(uv_udp_t *handle)
Definition: udp.c:129
uv_pipe_t queue
Definition: worker.c:9

References assert(), handle, NULL, queue, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_INSERT_TAIL, QUEUE_REMOVE, req, uv__io_active(), and uv__udp_run_completed().

Referenced by uv__finish_close().

◆ uv_pipe_listen()

int uv_pipe_listen ( uv_pipe_t handle,
int  backlog,
uv_connection_cb  cb 
)

Definition at line 94 of file pipe.c.

94  {
95  if (uv__stream_fd(handle) == -1)
96  return UV_EINVAL;
97 
98  if (handle->ipc)
99  return UV_EINVAL;
100 
101 #if defined(__MVS__) || defined(__PASE__)
102  /* On zOS, backlog=0 has undefined behaviour */
103  /* On IBMi PASE, backlog=0 leads to "Connection refused" error */
104  if (backlog == 0)
105  backlog = 1;
106  else if (backlog < 0)
107  backlog = SOMAXCONN;
108 #endif
109 
110  if (listen(uv__stream_fd(handle), backlog))
111  return UV__ERR(errno);
112 
113  handle->connection_cb = cb;
114  handle->io_watcher.cb = uv__server_io;
115  uv__io_start(handle->loop, &handle->io_watcher, POLLIN);
116  return 0;
117 }
static struct sockaddr static addrlen listen
Definition: sfsocketcall.h:116
void uv__server_io(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: stream.c:528

References cb, handle, listen, UV__ERR, uv__io_start(), uv__server_io(), and uv__stream_fd.

Referenced by uv_listen().

◆ uv_tcp_listen()

int uv_tcp_listen ( uv_tcp_t tcp,
int  backlog,
uv_connection_cb  cb 
)

Definition at line 328 of file tcp.c.

328  {
329  static int single_accept_cached = -1;
330  unsigned long flags;
331  int single_accept;
332  int err;
333 
334  if (tcp->delayed_error)
335  return tcp->delayed_error;
336 
337  single_accept = uv__load_relaxed(&single_accept_cached);
338  if (single_accept == -1) {
339  const char* val = getenv("UV_TCP_SINGLE_ACCEPT");
340  single_accept = (val != NULL && atoi(val) != 0); /* Off by default. */
341  uv__store_relaxed(&single_accept_cached, single_accept);
342  }
343 
344  if (single_accept)
345  tcp->flags |= UV_HANDLE_TCP_SINGLE_ACCEPT;
346 
347  flags = 0;
348 #if defined(__MVS__)
349  /* on zOS the listen call does not bind automatically
350  if the socket is unbound. Hence the manual binding to
351  an arbitrary port is required to be done manually
352  */
354 #endif
356  if (err)
357  return err;
358 
359  if (listen(tcp->io_watcher.fd, backlog))
360  return UV__ERR(errno);
361 
362  tcp->connection_cb = cb;
363  tcp->flags |= UV_HANDLE_BOUND;
364 
365  /* Start listening for connections. */
366  tcp->io_watcher.cb = uv__server_io;
367  uv__io_start(tcp->loop, &tcp->io_watcher, POLLIN);
368 
369  return 0;
370 }
ut16 val
Definition: armass64_const.h:6
static int maybe_new_socket(uv_tcp_t *handle, int domain, unsigned long flags)
Definition: tcp.c:67
@ UV_HANDLE_BOUND
Definition: uv-common.h:91

References AF_INET, cb, err, flags, getenv(), listen, maybe_new_socket(), NULL, UV__ERR, uv__io_start(), uv__load_relaxed, uv__server_io(), uv__store_relaxed, UV_HANDLE_BOUND, UV_HANDLE_TCP_SINGLE_ACCEPT, and val.

Referenced by uv_listen().

◆ UV_UNUSED() [1/2]

UV_UNUSED ( static char *  uv__basename_rconst char *path)

Definition at line 307 of file internal.h.

307  {
308  char* s;
309 
310  s = strrchr(path, '/');
311  if (s == NULL)
312  return (char*) path;
313 
314  return s + 1;
315 }

References NULL, path, and s.

◆ UV_UNUSED() [2/2]

UV_UNUSED ( static void   uv__update_timeuv_loop_t *loop)

Definition at line 301 of file internal.h.

301  {
302  /* Use a fast time source if available. We only need millisecond precision.
303  */
304  loop->time = uv__hrtime(UV_CLOCK_FAST) / 1000000;
305 }
uint64_t uv__hrtime(uv_clocktype_t type)
Definition: aix-common.c:43

References loop, uv__hrtime(), and UV_CLOCK_FAST.