Rizin
unix-like reverse engineering framework and cli tools
uv-common.c File Reference
#include "uv.h"
#include "uv-common.h"
#include <assert.h>
#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <net/if.h>
#include <sys/un.h>

Go to the source code of this file.

Classes

struct  uv__allocator_t
 

Macros

#define XX(uc, lc)   case UV_##uc: return sizeof(uv_##lc##_t);
 
#define UV_ERR_NAME_GEN_R(name, _)
 
#define UV_ERR_NAME_GEN(name, _)   case UV_ ## name: return #name;
 
#define UV_STRERROR_GEN_R(name, msg)
 
#define UV_STRERROR_GEN(name, msg)   case UV_ ## name: return msg;
 
#define X(uc, lc)   case UV_##uc: type = #lc; break;
 
#define uv__fs_scandir_free   free
 

Functions

char * uv__strdup (const char *s)
 
char * uv__strndup (const char *s, size_t n)
 
void * uv__malloc (size_t size)
 
void uv__free (void *ptr)
 
void * uv__calloc (size_t count, size_t size)
 
void * uv__realloc (void *ptr, size_t size)
 
void * uv__reallocf (void *ptr, size_t size)
 
int uv_replace_allocator (uv_malloc_func malloc_func, uv_realloc_func realloc_func, uv_calloc_func calloc_func, uv_free_func free_func)
 
size_t uv_handle_size (uv_handle_type type)
 
size_t uv_req_size (uv_req_type type)
 
size_t uv_loop_size (void)
 
uv_buf_t uv_buf_init (char *base, unsigned int len)
 
static const char * uv__unknown_err_code (int err)
 
char * uv_err_name_r (int err, char *buf, size_t buflen)
 
const char * uv_err_name (int err)
 
char * uv_strerror_r (int err, char *buf, size_t buflen)
 
const char * uv_strerror (int err)
 
int uv_ip4_addr (const char *ip, int port, struct sockaddr_in *addr)
 
int uv_ip6_addr (const char *ip, int port, struct sockaddr_in6 *addr)
 
int uv_ip4_name (const struct sockaddr_in *src, char *dst, size_t size)
 
int uv_ip6_name (const struct sockaddr_in6 *src, char *dst, size_t size)
 
int uv_tcp_bind (uv_tcp_t *handle, const struct sockaddr *addr, unsigned int flags)
 
int uv_udp_init_ex (uv_loop_t *loop, uv_udp_t *handle, unsigned flags)
 
int uv_udp_init (uv_loop_t *loop, uv_udp_t *handle)
 
int uv_udp_bind (uv_udp_t *handle, const struct sockaddr *addr, unsigned int flags)
 
int uv_tcp_connect (uv_connect_t *req, uv_tcp_t *handle, const struct sockaddr *addr, uv_connect_cb cb)
 
int uv_udp_connect (uv_udp_t *handle, const struct sockaddr *addr)
 
int uv__udp_is_connected (uv_udp_t *handle)
 
int uv__udp_check_before_send (uv_udp_t *handle, const struct sockaddr *addr)
 
int uv_udp_send (uv_udp_send_t *req, uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr, uv_udp_send_cb send_cb)
 
int uv_udp_try_send (uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr)
 
int uv_udp_recv_start (uv_udp_t *handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
 
int uv_udp_recv_stop (uv_udp_t *handle)
 
void uv_walk (uv_loop_t *loop, uv_walk_cb walk_cb, void *arg)
 
static void uv__print_handles (uv_loop_t *loop, int only_active, FILE *stream)
 
void uv_print_all_handles (uv_loop_t *loop, FILE *stream)
 
void uv_print_active_handles (uv_loop_t *loop, FILE *stream)
 
void uv_ref (uv_handle_t *handle)
 
void uv_unref (uv_handle_t *handle)
 
int uv_has_ref (const uv_handle_t *handle)
 
void uv_stop (uv_loop_t *loop)
 
uint64_t uv_now (const uv_loop_t *loop)
 
size_t uv__count_bufs (const uv_buf_t bufs[], unsigned int nbufs)
 
int uv_recv_buffer_size (uv_handle_t *handle, int *value)
 
int uv_send_buffer_size (uv_handle_t *handle, int *value)
 
int uv_fs_event_getpath (uv_fs_event_t *handle, char *buffer, size_t *size)
 
static unsigned intuv__get_nbufs (uv_fs_t *req)
 
void uv__fs_scandir_cleanup (uv_fs_t *req)
 
int uv_fs_scandir_next (uv_fs_t *req, uv_dirent_t *ent)
 
uv_dirent_type_t uv__fs_get_dirent_type (uv__dirent_t *dent)
 
void uv__fs_readdir_cleanup (uv_fs_t *req)
 
int uv_loop_configure (uv_loop_t *loop, uv_loop_option option,...)
 
uv_loop_tuv_default_loop (void)
 
uv_loop_tuv_loop_new (void)
 
int uv_loop_close (uv_loop_t *loop)
 
void uv_loop_delete (uv_loop_t *loop)
 
void uv_os_free_environ (uv_env_item_t *envitems, int count)
 
void uv_free_cpu_info (uv_cpu_info_t *cpu_infos, int count)
 
void uv_library_shutdown (void)
 
void uv__metrics_update_idle_time (uv_loop_t *loop)
 
void uv__metrics_set_provider_entry_time (uv_loop_t *loop)
 
uint64_t uv_metrics_idle_time (uv_loop_t *loop)
 

Variables

static uv__allocator_t uv__allocator
 
static uv_loop_t default_loop_struct
 
static uv_loop_tdefault_loop_ptr
 

Macro Definition Documentation

◆ uv__fs_scandir_free

#define uv__fs_scandir_free   free

Definition at line 632 of file uv-common.c.

◆ UV_ERR_NAME_GEN

#define UV_ERR_NAME_GEN (   name,
  _ 
)    case UV_ ## name: return #name;

Definition at line 188 of file uv-common.c.

◆ UV_ERR_NAME_GEN_R

#define UV_ERR_NAME_GEN_R (   name,
  _ 
)
Value:
case UV_## name: \
uv__strscpy(buf, #name, buflen); break;
voidpf void * buf
Definition: ioapi.h:138
const char * name
Definition: op.c:541
Definition: z80asm.h:102
ut64 buflen
Definition: core.c:76

Definition at line 175 of file uv-common.c.

◆ UV_STRERROR_GEN

#define UV_STRERROR_GEN (   name,
  msg 
)    case UV_ ## name: return msg;

Definition at line 211 of file uv-common.c.

◆ UV_STRERROR_GEN_R

#define UV_STRERROR_GEN_R (   name,
  msg 
)
Value:
case UV_ ## name: \
snprintf(buf, buflen, "%s", msg); break;
static struct sockaddr static addrlen static backlog const void msg
Definition: sfsocketcall.h:119

Definition at line 198 of file uv-common.c.

◆ X

#define X (   uc,
  lc 
)    case UV_##uc: type = #lc; break;

◆ XX

#define XX (   uc,
  lc 
)    case UV_##uc: return sizeof(uv_##lc##_t);

Definition at line 131 of file uv-common.c.

Function Documentation

◆ uv__calloc()

void* uv__calloc ( size_t  count,
size_t  size 
)

Definition at line 92 of file uv-common.c.

92  {
94 }
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
voidpf void uLong size
Definition: ioapi.h:138
uv_calloc_func local_calloc
Definition: uv-common.c:44
static uv__allocator_t uv__allocator
Definition: uv-common.c:48

References count, uv__allocator_t::local_calloc, and uv__allocator.

Referenced by uv__interface_addresses_v6(), uv__pipe_write_ipc(), uv_cpu_info(), uv_fs_poll_start(), uv_interface_addresses(), uv_loop_init(), and uv_os_environ().

◆ uv__count_bufs()

size_t uv__count_bufs ( const uv_buf_t  bufs[],
unsigned int  nbufs 
)

Definition at line 573 of file uv-common.c.

573  {
574  unsigned int i;
575  size_t bytes;
576 
577  bytes = 0;
578  for (i = 0; i < nbufs; i++)
579  bytes += (size_t) bufs[i].len;
580 
581  return bytes;
582 }
lzma_index ** i
Definition: index.h:629
static ut8 bytes[32]
Definition: asm_arc.c:23
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
Definition: util.c:18

References bufs, bytes, and i.

Referenced by uv__send(), uv__tty_try_write(), uv__udp_run_completed(), uv__udp_send(), uv__write_req_size(), uv_tcp_write(), uv_try_write(), and uv_write2().

◆ uv__free()

void uv__free ( void *  ptr)

Definition at line 81 of file uv-common.c.

81  {
82  int saved_errno;
83 
84  /* Libuv expects that free() does not clobber errno. The system allocator
85  * honors that assumption but custom allocators may not be so careful.
86  */
87  saved_errno = errno;
89  errno = saved_errno;
90 }
uv_free_func local_free
Definition: uv-common.c:45

References uv__allocator_t::local_free, and uv__allocator.

Referenced by child_fork(), eof_timer_close_cb(), epoll_queue_close(), freeifaddrs(), freeResultList(), fs__closedir(), fs__create_junction(), fs__opendir(), fs__readdir(), fs__realpath_handle(), fs__scandir(), fs__sendfile(), fs__statfs(), getNetlinkResponse(), make_program_args(), make_program_env(), maybe_free_watcher_list(), os390_readlink(), scandir(), search_path_join_test(), timer_close_cb(), uv__convert_utf16_to_utf8(), uv__convert_utf8_to_utf16(), uv__custom_sem_destroy(), uv__custom_sem_init(), uv__dlerror(), uv__fd_hash_remove(), uv__fs_closedir(), uv__fs_opendir(), uv__fs_read(), uv__fs_readdir(), uv__fs_readdir_cleanup(), uv__fs_readlink(), uv__fs_realpath(), uv__fs_write_all(), uv__getaddrinfo_done(), uv__getpwuid_r(), uv__inotify_fork(), uv__io_fork(), uv__loop_close(), uv__loops_remove(), uv__pipe_close(), uv__pipe_getname(), uv__pipe_write_ipc(), uv__platform_loop_delete(), uv__process_title_cleanup(), uv__realloc(), uv__reallocf(), uv__search_path(), uv__stdio_destroy(), uv__stream_close(), uv__thread_start(), uv__threadpool_cleanup(), uv__udp_run_completed(), uv__write_callbacks(), uv__write_req_finish(), uv_accept(), uv_barrier_destroy(), uv_barrier_init(), uv_chdir(), uv_cpu_info(), uv_cwd(), uv_dlclose(), uv_exepath(), uv_free_cpu_info(), uv_free_interface_addresses(), uv_freeaddrinfo(), uv_fs_event_endgame(), uv_fs_event_start(), uv_fs_event_stop(), uv_fs_poll_start(), uv_fs_req_cleanup(), uv_getaddrinfo(), uv_interface_addresses(), uv_loop_delete(), uv_loop_init(), uv_loop_new(), uv_os_environ(), uv_os_free_environ(), uv_os_free_passwd(), uv_os_getenv(), uv_os_setenv(), uv_os_tmpdir(), uv_os_unsetenv(), uv_pipe_accept(), uv_pipe_bind(), uv_pipe_chmod(), uv_pipe_cleanup(), uv_pipe_connect(), uv_pipe_endgame(), uv_process_fs_event_req(), uv_process_pipe_write_req(), uv_set_process_title(), uv_spawn(), uv_split_path(), uv_tcp_endgame(), uv_thread_create_ex(), uv_try_write(), and uv_uptime().

◆ uv__fs_get_dirent_type()

uv_dirent_type_t uv__fs_get_dirent_type ( uv__dirent_t dent)

Definition at line 688 of file uv-common.c.

688  {
690 
691 #ifdef HAVE_DIRENT_TYPES
692  switch (dent->d_type) {
693  case UV__DT_DIR:
695  break;
696  case UV__DT_FILE:
698  break;
699  case UV__DT_LINK:
701  break;
702  case UV__DT_FIFO:
704  break;
705  case UV__DT_SOCKET:
707  break;
708  case UV__DT_CHAR:
710  break;
711  case UV__DT_BLOCK:
713  break;
714  default:
716  }
717 #else
719 #endif
720 
721  return type;
722 }
int type
Definition: mipsasm.c:17
uv_dirent_type_t
Definition: uv.h:1139
@ UV_DIRENT_FIFO
Definition: uv.h:1144
@ UV_DIRENT_CHAR
Definition: uv.h:1146
@ UV_DIRENT_DIR
Definition: uv.h:1142
@ UV_DIRENT_UNKNOWN
Definition: uv.h:1140
@ UV_DIRENT_BLOCK
Definition: uv.h:1147
@ UV_DIRENT_LINK
Definition: uv.h:1143
@ UV_DIRENT_FILE
Definition: uv.h:1141
@ UV_DIRENT_SOCKET
Definition: uv.h:1145
#define UV__DT_SOCKET
Definition: win.h:314
#define UV__DT_FILE
Definition: win.h:311
#define UV__DT_FIFO
Definition: win.h:313
#define UV__DT_CHAR
Definition: win.h:315
#define UV__DT_DIR
Definition: win.h:310
#define UV__DT_BLOCK
Definition: win.h:316
#define UV__DT_LINK
Definition: win.h:312

References type, UV__DT_BLOCK, UV__DT_CHAR, UV__DT_DIR, UV__DT_FIFO, UV__DT_FILE, UV__DT_LINK, UV__DT_SOCKET, UV_DIRENT_BLOCK, UV_DIRENT_CHAR, UV_DIRENT_DIR, UV_DIRENT_FIFO, UV_DIRENT_FILE, UV_DIRENT_LINK, UV_DIRENT_SOCKET, and UV_DIRENT_UNKNOWN.

Referenced by fs__readdir(), uv__fs_readdir(), and uv_fs_scandir_next().

◆ uv__fs_readdir_cleanup()

void uv__fs_readdir_cleanup ( uv_fs_t req)

Definition at line 724 of file uv-common.c.

724  {
725  uv_dir_t* dir;
726  uv_dirent_t* dirents;
727  int i;
728 
729  if (req->ptr == NULL)
730  return;
731 
732  dir = req->ptr;
733  dirents = dir->dirents;
734  req->ptr = NULL;
735 
736  if (dirents == NULL)
737  return;
738 
739  for (i = 0; i < req->result; ++i) {
740  uv__free((char*) dirents[i].name);
741  dirents[i].name = NULL;
742  }
743 }
#define NULL
Definition: cris-opc.c:27
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
Definition: uv.h:1298
uv_dirent_t * dirents
Definition: uv.h:1299
const char * name
Definition: uv.h:1151
void uv__free(void *ptr)
Definition: uv-common.c:81

References uv_dir_s::dirents, i, uv_dirent_s::name, NULL, req, and uv__free().

Referenced by uv_fs_req_cleanup().

◆ uv__fs_scandir_cleanup()

void uv__fs_scandir_cleanup ( uv_fs_t req)

Definition at line 635 of file uv-common.c.

635  {
636  uv__dirent_t** dents;
637 
638  unsigned int* nbufs = uv__get_nbufs(req);
639 
640  dents = req->ptr;
641  if (*nbufs > 0 && *nbufs != (unsigned int) req->result)
642  (*nbufs)--;
643  for (; *nbufs < (unsigned int) req->result; (*nbufs)++)
644  uv__fs_scandir_free(dents[*nbufs]);
645 
646  uv__fs_scandir_free(req->ptr);
647  req->ptr = NULL;
648 }
static int
Definition: sfsocketcall.h:114
Definition: sftypes.h:48
#define uv__fs_scandir_free
Definition: uv-common.c:632
static unsigned int * uv__get_nbufs(uv_fs_t *req)
Definition: uv-common.c:617

References int, NULL, req, uv__fs_scandir_free, and uv__get_nbufs().

Referenced by uv_fs_req_cleanup().

◆ uv__get_nbufs()

static unsigned int* uv__get_nbufs ( uv_fs_t req)
static

Definition at line 617 of file uv-common.c.

617  {
618 #ifdef _WIN32
619  return &req->fs.info.nbufs;
620 #else
621  return &req->nbufs;
622 #endif
623 }

References req.

Referenced by uv__fs_scandir_cleanup(), and uv_fs_scandir_next().

◆ uv__malloc()

void* uv__malloc ( size_t  size)

Definition at line 75 of file uv-common.c.

75  {
76  if (size > 0)
78  return NULL;
79 }
uv_malloc_func local_malloc
Definition: uv-common.c:42

References uv__allocator_t::local_malloc, NULL, and uv__allocator.

Referenced by eof_timer_init(), epoll_create1(), fs__capture_path(), fs__create_junction(), fs__opendir(), fs__realpath_handle(), fs__scandir(), fs__sendfile(), fs__statfs(), fs__wide_to_utf8(), getNetlinkResponse(), init_threads(), interpretAddr(), interpretLink(), make_program_args(), make_program_env(), newListItem(), os390_readlink(), scandir(), search_path_join_test(), uv__build_coalesced_write_req(), uv__convert_utf16_to_utf8(), uv__convert_utf8_to_utf16(), uv__custom_sem_init(), uv__fd_hash_add(), uv__fs_opendir(), uv__fs_readlink(), uv__fs_realpath(), uv__fs_statfs(), uv__getaddrinfo_done(), uv__getpwuid_r(), uv__interface_addresses_v6(), uv__pipe_getname(), uv__pipe_queue_ipc_xfer_info(), uv__stdio_create(), uv__strdup(), uv__stream_queue_fd(), uv__strndup(), uv__udp_send(), uv_barrier_init(), uv_chdir(), uv_cpu_info(), uv_cwd(), uv_exepath(), uv_fs_event_start(), uv_fs_read(), uv_fs_write(), uv_getaddrinfo(), uv_interface_addresses(), uv_loop_init(), uv_loop_new(), uv_os_getenv(), uv_os_tmpdir(), uv_pipe_bind(), uv_pipe_chmod(), uv_pipe_connect(), uv_process_fs_event_req(), uv_relative_path(), uv_set_process_title(), uv_setup_args(), uv_spawn(), uv_split_path(), uv_tcp_listen(), uv_thread_create_ex(), uv_uptime(), uv_utf8_to_utf16_alloc(), and uv_write2().

◆ uv__metrics_set_provider_entry_time()

void uv__metrics_set_provider_entry_time ( uv_loop_t loop)

Definition at line 899 of file uv-common.c.

899  {
900  uv__loop_metrics_t* loop_metrics;
901  uint64_t now;
902 
904  return;
905 
906  now = uv_hrtime();
907  loop_metrics = uv__get_loop_metrics(loop);
908  uv_mutex_lock(&loop_metrics->lock);
909  loop_metrics->provider_entry_time = now;
910  uv_mutex_unlock(&loop_metrics->lock);
911 }
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
unsigned long uint64_t
Definition: sftypes.h:28
uv_mutex_t lock
Definition: uv-common.h:357
uint64_t provider_entry_time
Definition: uv-common.h:355
uv_loop_t * loop
Definition: main.c:7
#define uv__get_loop_metrics(loop)
Definition: uv-common.h:339
#define uv__get_internal_fields(loop)
Definition: uv-common.h:336
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330
UV_EXTERN uint64_t uv_hrtime(void)
Definition: core.c:103
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350
@ UV_METRICS_IDLE_TIME
Definition: uv.h:251

References flags, uv__loop_metrics_s::lock, loop, uv__loop_metrics_s::provider_entry_time, uv__get_internal_fields, uv__get_loop_metrics, uv_hrtime(), UV_METRICS_IDLE_TIME, uv_mutex_lock(), and uv_mutex_unlock().

Referenced by uv__io_poll(), uv__poll(), and uv__poll_wine().

◆ uv__metrics_update_idle_time()

void uv__metrics_update_idle_time ( uv_loop_t loop)

Definition at line 872 of file uv-common.c.

872  {
873  uv__loop_metrics_t* loop_metrics;
874  uint64_t entry_time;
875  uint64_t exit_time;
876 
878  return;
879 
880  loop_metrics = uv__get_loop_metrics(loop);
881 
882  /* The thread running uv__metrics_update_idle_time() is always the same
883  * thread that sets provider_entry_time. So it's unnecessary to lock before
884  * retrieving this value.
885  */
886  if (loop_metrics->provider_entry_time == 0)
887  return;
888 
889  exit_time = uv_hrtime();
890 
891  uv_mutex_lock(&loop_metrics->lock);
892  entry_time = loop_metrics->provider_entry_time;
893  loop_metrics->provider_entry_time = 0;
894  loop_metrics->provider_idle_time += exit_time - entry_time;
895  uv_mutex_unlock(&loop_metrics->lock);
896 }
uint64_t provider_idle_time
Definition: uv-common.h:356

References flags, uv__loop_metrics_s::lock, loop, uv__loop_metrics_s::provider_entry_time, uv__loop_metrics_s::provider_idle_time, uv__get_internal_fields, uv__get_loop_metrics, uv_hrtime(), UV_METRICS_IDLE_TIME, uv_mutex_lock(), and uv_mutex_unlock().

Referenced by uv__io_poll(), uv__poll(), uv__poll_wine(), and uv_run().

◆ uv__print_handles()

static void uv__print_handles ( uv_loop_t loop,
int  only_active,
FILE *  stream 
)
static

Definition at line 505 of file uv-common.c.

505  {
506  const char* type;
507  QUEUE* q;
508  uv_handle_t* h;
509 
510  if (loop == NULL)
511  loop = uv_default_loop();
512 
514  h = QUEUE_DATA(q, uv_handle_t, handle_queue);
515 
516  if (only_active && !uv__is_active(h))
517  continue;
518 
519  switch (h->type) {
520 #define X(uc, lc) case UV_##uc: type = #lc; break;
522 #undef X
523  default: type = "<unknown>";
524  }
525 
526  fprintf(stream,
527  "[%c%c%c] %-8s %p\n",
528  "R-"[!(h->flags & UV_HANDLE_REF)],
529  "A-"[!(h->flags & UV_HANDLE_ACTIVE)],
530  "I-"[!(h->flags & UV_HANDLE_INTERNAL)],
531  type,
532  (void*)h);
533  }
534 }
voidpf stream
Definition: ioapi.h:138
#define QUEUE_FOREACH(q, h)
Definition: queue.h:36
#define QUEUE_DATA(ptr, type, field)
Definition: queue.h:30
void * QUEUE[2]
Definition: queue.h:21
#define h(i)
Definition: sha256.c:48
void * handle_queue[2]
Definition: uv.h:1785
uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:763
#define X(uc, lc)
@ UV_HANDLE_REF
Definition: uv-common.h:77
@ UV_HANDLE_INTERNAL
Definition: uv-common.h:78
@ UV_HANDLE_ACTIVE
Definition: uv-common.h:76
#define uv__is_active(h)
Definition: uv-common.h:252
#define UV_HANDLE_TYPE_MAP(XX)
Definition: uv.h:152

References h, uv_loop_s::handle_queue, loop, NULL, QUEUE_DATA, QUEUE_FOREACH, type, uv__is_active, uv_default_loop(), UV_HANDLE_ACTIVE, UV_HANDLE_INTERNAL, UV_HANDLE_REF, UV_HANDLE_TYPE_MAP, and X.

Referenced by uv_print_active_handles(), and uv_print_all_handles().

◆ uv__realloc()

void* uv__realloc ( void *  ptr,
size_t  size 
)

Definition at line 96 of file uv-common.c.

96  {
97  if (size > 0)
98  return uv__allocator.local_realloc(ptr, size);
99  uv__free(ptr);
100  return NULL;
101 }
uv_realloc_func local_realloc
Definition: uv-common.c:43

References uv__allocator_t::local_realloc, NULL, uv__allocator, and uv__free().

Referenced by fs__scandir(), scandir(), uv__loops_add(), uv__loops_remove(), uv__reallocf(), and uv__stream_queue_fd().

◆ uv__reallocf()

void* uv__reallocf ( void *  ptr,
size_t  size 
)

Definition at line 103 of file uv-common.c.

103  {
104  void* newptr;
105 
106  newptr = uv__realloc(ptr, size);
107  if (newptr == NULL)
108  if (size > 0)
109  uv__free(ptr);
110 
111  return newptr;
112 }
void * uv__realloc(void *ptr, size_t size)
Definition: uv-common.c:96

References NULL, uv__free(), and uv__realloc().

Referenced by fs__statfs(), maybe_resize(), uv__fs_readlink(), uv__pollfds_maybe_resize(), and uv_exepath().

◆ uv__strdup()

char* uv__strdup ( const char *  s)

Definition at line 55 of file uv-common.c.

55  {
56  size_t len = strlen(s) + 1;
57  char* m = uv__malloc(len);
58  if (m == NULL)
59  return NULL;
60  return memcpy(m, s, len);
61 }
size_t len
Definition: 6502dis.c:15
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static RzSocket * s
Definition: rtr.c:28
void * uv__malloc(size_t size)
Definition: uv-common.c:75

References len, regress::m, memcpy(), NULL, s, and uv__malloc().

Referenced by uv__dlerror(), uv__fs_readdir(), uv__inotify_fork(), uv__interface_addresses_v6(), uv__search_path(), uv__unknown_err_code(), uv_cpu_info(), uv_fs_event_start(), uv_fs_mkdtemp(), uv_fs_mkstemp(), uv_interface_addresses(), uv_os_environ(), uv_pipe_bind(), uv_set_process_title(), and uv_setup_args().

◆ uv__strndup()

char* uv__strndup ( const char *  s,
size_t  n 
)

Definition at line 63 of file uv-common.c.

63  {
64  char* m;
65  size_t len = strlen(s);
66  if (n < len)
67  len = n;
68  m = uv__malloc(len + 1);
69  if (m == NULL)
70  return NULL;
71  m[len] = '\0';
72  return memcpy(m, s, len);
73 }
int n
Definition: mipsasm.c:19

References len, regress::m, memcpy(), n, NULL, s, and uv__malloc().

Referenced by read_models().

◆ uv__udp_check_before_send()

int uv__udp_check_before_send ( uv_udp_t handle,
const struct sockaddr addr 
)

Definition at line 407 of file uv-common.c.

407  {
408  unsigned int addrlen;
409 
410  if (handle->type != UV_UDP)
411  return UV_EINVAL;
412 
413  if (addr != NULL && (handle->flags & UV_HANDLE_UDP_CONNECTED))
414  return UV_EISCONN;
415 
416  if (addr == NULL && !(handle->flags & UV_HANDLE_UDP_CONNECTED))
417  return UV_EDESTADDRREQ;
418 
419  if (addr != NULL) {
420  if (addr->sa_family == AF_INET)
421  addrlen = sizeof(struct sockaddr_in);
422  else if (addr->sa_family == AF_INET6)
423  addrlen = sizeof(struct sockaddr_in6);
424 #if defined(AF_UNIX) && !defined(_WIN32)
425  else if (addr->sa_family == AF_UNIX)
426  addrlen = sizeof(struct sockaddr_un);
427 #endif
428  else
429  return UV_EINVAL;
430  } else {
431  addrlen = 0;
432  }
433 
434  return addrlen;
435 }
static mcore_handle handle
Definition: asm_mcore.c:8
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 struct sockaddr addrlen
Definition: sflib.h:75
#define AF_UNIX
Definition: sftypes.h:285
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
@ UV_HANDLE_UDP_CONNECTED
Definition: uv-common.h:114
static int addr
Definition: z80asm.c:58

References addr, addrlen, AF_INET, AF_INET6, AF_UNIX, handle, NULL, and UV_HANDLE_UDP_CONNECTED.

Referenced by uv_udp_send(), and uv_udp_try_send().

◆ uv__udp_is_connected()

int uv__udp_is_connected ( uv_udp_t handle)

Definition at line 393 of file uv-common.c.

393  {
394  struct sockaddr_storage addr;
395  int addrlen;
396  if (handle->type != UV_UDP)
397  return 0;
398 
399  addrlen = sizeof(addr);
400  if (uv_udp_getpeername(handle, (struct sockaddr*) &addr, &addrlen) != 0)
401  return 0;
402 
403  return addrlen > 0;
404 }
UV_EXTERN int uv_udp_getpeername(const uv_udp_t *handle, struct sockaddr *name, int *namelen)
Definition: udp.c:1276

References addr, addrlen, handle, and uv_udp_getpeername().

Referenced by uv_udp_open().

◆ uv__unknown_err_code()

static const char* uv__unknown_err_code ( int  err)
static

Definition at line 165 of file uv-common.c.

165  {
166  char buf[32];
167  char* copy;
168 
169  snprintf(buf, sizeof(buf), "Unknown system error %d", err);
170  copy = uv__strdup(buf);
171 
172  return copy != NULL ? copy : "Unknown system error";
173 }
static bool err
Definition: armass.c:435
snprintf
Definition: kernel.h:364
char * uv__strdup(const char *s)
Definition: uv-common.c:55

References err, NULL, snprintf, and uv__strdup().

Referenced by uv_err_name(), and uv_strerror().

◆ uv_buf_init()

◆ uv_default_loop()

uv_loop_t* uv_default_loop ( void  )

Definition at line 763 of file uv-common.c.

763  {
764  if (default_loop_ptr != NULL)
765  return default_loop_ptr;
766 
768  return NULL;
769 
771  return default_loop_ptr;
772 }
static uv_loop_t * default_loop_ptr
Definition: uv-common.c:760
static uv_loop_t default_loop_struct
Definition: uv-common.c:759
UV_EXTERN int uv_loop_init(uv_loop_t *loop)
Definition: loop.c:30

References default_loop_ptr, default_loop_struct, NULL, and uv_loop_init().

Referenced by idle_cb(), main(), on_open(), on_read(), on_write(), and uv__print_handles().

◆ uv_err_name()

const char* uv_err_name ( int  err)

Definition at line 189 of file uv-common.c.

189  {
190  switch (err) {
192  }
193  return uv__unknown_err_code(err);
194 }
#define UV_ERR_NAME_GEN(name, _)
Definition: uv-common.c:188
static const char * uv__unknown_err_code(int err)
Definition: uv-common.c:165
#define UV_ERRNO_MAP(XX)
Definition: uv.h:70

References err, uv__unknown_err_code(), UV_ERR_NAME_GEN, and UV_ERRNO_MAP.

Referenced by echo_read(), echo_write(), main(), on_connect(), on_new_connection(), on_read(), and on_resolved().

◆ uv_err_name_r()

char* uv_err_name_r ( int  err,
char *  buf,
size_t  buflen 
)

Definition at line 178 of file uv-common.c.

178  {
179  switch (err) {
181  default: snprintf(buf, buflen, "Unknown system error %d", err);
182  }
183  return buf;
184 }
#define UV_ERR_NAME_GEN_R(name, _)
Definition: uv-common.c:175

References buflen, err, snprintf, UV_ERR_NAME_GEN_R, and UV_ERRNO_MAP.

◆ uv_free_cpu_info()

void uv_free_cpu_info ( uv_cpu_info_t cpu_infos,
int  count 
)

Definition at line 846 of file uv-common.c.

846  {
847  int i;
848 
849  for (i = 0; i < count; i++)
850  uv__free(cpu_infos[i].model);
851 
852  uv__free(cpu_infos);
853 }

References count, i, and uv__free().

Referenced by setup_workers(), and uv_cpu_info().

◆ uv_fs_event_getpath()

int uv_fs_event_getpath ( uv_fs_event_t handle,
char *  buffer,
size_t size 
)

Definition at line 592 of file uv-common.c.

592  {
593  size_t required_len;
594 
595  if (!uv__is_active(handle)) {
596  *size = 0;
597  return UV_EINVAL;
598  }
599 
600  required_len = strlen(handle->path);
601  if (required_len >= *size) {
602  *size = required_len + 1;
603  return UV_ENOBUFS;
604  }
605 
606  memcpy(buffer, handle->path, required_len);
607  *size = required_len;
608  buffer[required_len] = '\0';
609 
610  return 0;
611 }
Definition: buffer.h:15

References handle, memcpy(), and uv__is_active.

Referenced by run_command().

◆ uv_fs_scandir_next()

int uv_fs_scandir_next ( uv_fs_t req,
uv_dirent_t ent 
)

Definition at line 651 of file uv-common.c.

651  {
652  uv__dirent_t** dents;
653  uv__dirent_t* dent;
654  unsigned int* nbufs;
655 
656  /* Check to see if req passed */
657  if (req->result < 0)
658  return req->result;
659 
660  /* Ptr will be null if req was canceled or no files found */
661  if (!req->ptr)
662  return UV_EOF;
663 
664  nbufs = uv__get_nbufs(req);
665  assert(nbufs);
666 
667  dents = req->ptr;
668 
669  /* Free previous entity */
670  if (*nbufs > 0)
671  uv__fs_scandir_free(dents[*nbufs - 1]);
672 
673  /* End was already reached */
674  if (*nbufs == (unsigned int) req->result) {
675  uv__fs_scandir_free(dents);
676  req->ptr = NULL;
677  return UV_EOF;
678  }
679 
680  dent = dents[(*nbufs)++];
681 
682  ent->name = dent->d_name;
683  ent->type = uv__fs_get_dirent_type(dent);
684 
685  return 0;
686 }
assert(limit<=UINT32_MAX/2)
char d_name[256]
Definition: sftypes.h:52
uv_dirent_type_t type
Definition: uv.h:1152
uv_dirent_type_t uv__fs_get_dirent_type(uv__dirent_t *dent)
Definition: uv-common.c:688

References assert(), dirent::d_name, uv_dirent_s::name, NULL, req, uv_dirent_s::type, uv__fs_get_dirent_type(), uv__fs_scandir_free, and uv__get_nbufs().

◆ uv_handle_size()

size_t uv_handle_size ( uv_handle_type  type)

Definition at line 133 of file uv-common.c.

133  {
134  switch (type) {
136  default:
137  return -1;
138  }
139 }
#define XX(uc, lc)
Definition: uv-common.c:131

References type, UV_HANDLE_TYPE_MAP, and XX.

◆ uv_has_ref()

int uv_has_ref ( const uv_handle_t handle)

Definition at line 557 of file uv-common.c.

557  {
558  return uv__has_ref(handle);
559 }
#define uv__has_ref(h)
Definition: uv-common.h:292

References handle, and uv__has_ref.

◆ uv_ip4_addr()

int uv_ip4_addr ( const char *  ip,
int  port,
struct sockaddr_in addr 
)

Definition at line 221 of file uv-common.c.

221  {
222  memset(addr, 0, sizeof(*addr));
223  addr->sin_family = AF_INET;
224  addr->sin_port = htons(port);
225 #ifdef SIN6_LEN
226  addr->sin_len = sizeof(*addr);
227 #endif
228  return uv_inet_pton(AF_INET, ip, &(addr->sin_addr.s_addr));
229 }
return memset(p, 0, total)
#define ip
#define htons(x)
Definition: sftypes.h:475
UV_EXTERN int uv_inet_pton(int af, const char *src, void *dst)
Definition: inet.c:150

References addr, AF_INET, htons, ip, memset(), and uv_inet_pton().

Referenced by main(), uv_udp_set_membership(), uv_udp_set_multicast_interface(), uv_udp_set_source_membership(), and uv_winsock_init().

◆ uv_ip4_name()

int uv_ip4_name ( const struct sockaddr_in src,
char *  dst,
size_t  size 
)

Definition at line 267 of file uv-common.c.

267  {
268  return uv_inet_ntop(AF_INET, &src->sin_addr, dst, size);
269 }
lzma_index * src
Definition: index.h:567
char * dst
Definition: lz4.h:724
UV_EXTERN int uv_inet_ntop(int af, const void *src, char *dst, size_t size)
Definition: inet.c:40

References AF_INET, dst, src, and uv_inet_ntop().

Referenced by main(), on_read(), and on_resolved().

◆ uv_ip6_addr()

int uv_ip6_addr ( const char *  ip,
int  port,
struct sockaddr_in6 addr 
)

Definition at line 232 of file uv-common.c.

232  {
233  char address_part[40];
234  size_t address_part_size;
235  const char* zone_index;
236 
237  memset(addr, 0, sizeof(*addr));
238  addr->sin6_family = AF_INET6;
239  addr->sin6_port = htons(port);
240 #ifdef SIN6_LEN
241  addr->sin6_len = sizeof(*addr);
242 #endif
243 
244  zone_index = strchr(ip, '%');
245  if (zone_index != NULL) {
246  address_part_size = zone_index - ip;
247  if (address_part_size >= sizeof(address_part))
248  address_part_size = sizeof(address_part) - 1;
249 
250  memcpy(address_part, ip, address_part_size);
251  address_part[address_part_size] = '\0';
252  ip = address_part;
253 
254  zone_index++; /* skip '%' */
255  /* NOTE: unknown interface (id=0) is silently ignored */
256 #ifdef _WIN32
257  addr->sin6_scope_id = atoi(zone_index);
258 #else
259  addr->sin6_scope_id = if_nametoindex(zone_index);
260 #endif
261  }
262 
263  return uv_inet_pton(AF_INET6, ip, &addr->sin6_addr);
264 }

References addr, AF_INET6, htons, ip, memcpy(), memset(), NULL, and uv_inet_pton().

Referenced by uv__udp_set_membership6(), uv__udp_set_source_membership6(), uv_udp_set_membership(), uv_udp_set_multicast_interface(), uv_udp_set_source_membership(), and uv_winsock_init().

◆ uv_ip6_name()

int uv_ip6_name ( const struct sockaddr_in6 src,
char *  dst,
size_t  size 
)

Definition at line 272 of file uv-common.c.

272  {
273  return uv_inet_ntop(AF_INET6, &src->sin6_addr, dst, size);
274 }

References AF_INET6, dst, src, and uv_inet_ntop().

Referenced by main().

◆ uv_library_shutdown()

void uv_library_shutdown ( void  )

Definition at line 859 of file uv-common.c.

859  {
860  static int was_shutdown;
861 
862  if (uv__load_relaxed(&was_shutdown))
863  return;
864 
868  uv__store_relaxed(&was_shutdown, 1);
869 }
void uv__process_title_cleanup(void)
Definition: aix.c:987
void uv__signal_cleanup(void)
Definition: signal.c:80
void uv__threadpool_cleanup(void)
Definition: threadpool.c:163
#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, uv__process_title_cleanup(), uv__signal_cleanup(), uv__store_relaxed, and uv__threadpool_cleanup().

◆ uv_loop_close()

int uv_loop_close ( uv_loop_t loop)

Definition at line 791 of file uv-common.c.

791  {
792  QUEUE* q;
793  uv_handle_t* h;
794 #ifndef NDEBUG
795  void* saved_data;
796 #endif
797 
799  return UV_EBUSY;
800 
802  h = QUEUE_DATA(q, uv_handle_t, handle_queue);
803  if (!(h->flags & UV_HANDLE_INTERNAL))
804  return UV_EBUSY;
805  }
806 
808 
809 #ifndef NDEBUG
810  saved_data = loop->data;
811  memset(loop, -1, sizeof(*loop));
812  loop->data = saved_data;
813 #endif
814  if (loop == default_loop_ptr)
816 
817  return 0;
818 }
void uv__loop_close(uv_loop_t *loop)
Definition: loop.c:165
void * data
Definition: uv.h:1782
#define uv__has_active_reqs(loop)
Definition: uv-common.h:221

References uv_loop_s::data, default_loop_ptr, h, uv_loop_s::handle_queue, loop, memset(), NULL, QUEUE_DATA, QUEUE_FOREACH, uv__has_active_reqs, uv__loop_close(), and UV_HANDLE_INTERNAL.

Referenced by main(), and uv_loop_delete().

◆ uv_loop_configure()

int uv_loop_configure ( uv_loop_t loop,
uv_loop_option  option,
  ... 
)

Definition at line 746 of file uv-common.c.

746  {
747  va_list ap;
748  int err;
749 
750  va_start(ap, option);
751  /* Any platform-agnostic options should be handled here. */
753  va_end(ap);
754 
755  return err;
756 }
int uv__loop_configure(uv_loop_t *loop, uv_loop_option option, va_list ap)
Definition: loop.c:211
Definition: getopt.h:84

References err, loop, and uv__loop_configure().

◆ uv_loop_delete()

void uv_loop_delete ( uv_loop_t loop)

Definition at line 821 of file uv-common.c.

821  {
822  uv_loop_t* default_loop;
823  int err;
824 
825  default_loop = default_loop_ptr;
826 
828  (void) err; /* Squelch compiler warnings. */
829  assert(err == 0);
830  if (loop != default_loop)
831  uv__free(loop);
832 }
Definition: uv.h:1780
int uv_loop_close(uv_loop_t *loop)
Definition: uv-common.c:791

References assert(), default_loop_ptr, err, loop, uv__free(), and uv_loop_close().

◆ uv_loop_new()

uv_loop_t* uv_loop_new ( void  )

Definition at line 775 of file uv-common.c.

775  {
776  uv_loop_t* loop;
777 
778  loop = uv__malloc(sizeof(*loop));
779  if (loop == NULL)
780  return NULL;
781 
782  if (uv_loop_init(loop)) {
783  uv__free(loop);
784  return NULL;
785  }
786 
787  return loop;
788 }

References loop, NULL, uv__free(), uv__malloc(), and uv_loop_init().

◆ uv_loop_size()

size_t uv_loop_size ( void  )

Definition at line 152 of file uv-common.c.

152  {
153  return sizeof(uv_loop_t);
154 }
struct uv_loop_s uv_loop_t
Definition: uv.h:209

◆ uv_metrics_idle_time()

uint64_t uv_metrics_idle_time ( uv_loop_t loop)

Definition at line 914 of file uv-common.c.

914  {
915  uv__loop_metrics_t* loop_metrics;
916  uint64_t entry_time;
917  uint64_t idle_time;
918 
919  loop_metrics = uv__get_loop_metrics(loop);
920  uv_mutex_lock(&loop_metrics->lock);
921  idle_time = loop_metrics->provider_idle_time;
922  entry_time = loop_metrics->provider_entry_time;
923  uv_mutex_unlock(&loop_metrics->lock);
924 
925  if (entry_time > 0)
926  idle_time += uv_hrtime() - entry_time;
927  return idle_time;
928 }

References uv__loop_metrics_s::lock, loop, uv__loop_metrics_s::provider_entry_time, uv__loop_metrics_s::provider_idle_time, uv__get_loop_metrics, uv_hrtime(), uv_mutex_lock(), and uv_mutex_unlock().

◆ uv_now()

uint64_t uv_now ( const uv_loop_t loop)

Definition at line 567 of file uv-common.c.

567  {
568  return loop->time;
569 }

References loop.

Referenced by poll_cb(), timer_cb(), and uv_fs_poll_start().

◆ uv_os_free_environ()

void uv_os_free_environ ( uv_env_item_t envitems,
int  count 
)

Definition at line 835 of file uv-common.c.

835  {
836  int i;
837 
838  for (i = 0; i < count; i++) {
839  uv__free(envitems[i].name);
840  }
841 
842  uv__free(envitems);
843 }

References count, i, and uv__free().

◆ uv_print_active_handles()

void uv_print_active_handles ( uv_loop_t loop,
FILE *  stream 
)

Definition at line 542 of file uv-common.c.

542  {
544 }
static void uv__print_handles(uv_loop_t *loop, int only_active, FILE *stream)
Definition: uv-common.c:505

References loop, and uv__print_handles().

◆ uv_print_all_handles()

void uv_print_all_handles ( uv_loop_t loop,
FILE *  stream 
)

Definition at line 537 of file uv-common.c.

537  {
539 }

References loop, and uv__print_handles().

◆ uv_recv_buffer_size()

int uv_recv_buffer_size ( uv_handle_t handle,
int value 
)

Definition at line 584 of file uv-common.c.

584  {
586 }
static int value
Definition: cmd_api.c:93
#define SO_RCVBUF
Definition: sftypes.h:436
int uv__socket_sockopt(uv_handle_t *handle, int optname, int *value)
Definition: core.c:180

References handle, SO_RCVBUF, uv__socket_sockopt(), and value.

◆ uv_ref()

void uv_ref ( uv_handle_t handle)

Definition at line 547 of file uv-common.c.

547  {
549 }
#define uv__handle_ref(h)
Definition: uv-common.h:274

References handle, and uv__handle_ref.

◆ uv_replace_allocator()

int uv_replace_allocator ( uv_malloc_func  malloc_func,
uv_realloc_func  realloc_func,
uv_calloc_func  calloc_func,
uv_free_func  free_func 
)

Definition at line 114 of file uv-common.c.

117  {
118  if (malloc_func == NULL || realloc_func == NULL ||
119  calloc_func == NULL || free_func == NULL) {
120  return UV_EINVAL;
121  }
122 
123  uv__allocator.local_malloc = malloc_func;
124  uv__allocator.local_realloc = realloc_func;
125  uv__allocator.local_calloc = calloc_func;
126  uv__allocator.local_free = free_func;
127 
128  return 0;
129 }

References uv__allocator_t::local_calloc, uv__allocator_t::local_free, uv__allocator_t::local_malloc, uv__allocator_t::local_realloc, NULL, and uv__allocator.

◆ uv_req_size()

size_t uv_req_size ( uv_req_type  type)

Definition at line 141 of file uv-common.c.

141  {
142  switch(type) {
144  default:
145  return -1;
146  }
147 }
#define UV_REQ_TYPE_MAP(XX)
Definition: uv.h:170

References type, UV_REQ_TYPE_MAP, and XX.

◆ uv_send_buffer_size()

int uv_send_buffer_size ( uv_handle_t handle,
int value 
)

Definition at line 588 of file uv-common.c.

588  {
590 }
#define SO_SNDBUF
Definition: sftypes.h:435

References handle, SO_SNDBUF, uv__socket_sockopt(), and value.

◆ uv_stop()

void uv_stop ( uv_loop_t loop)

Definition at line 562 of file uv-common.c.

562  {
563  loop->stop_flag = 1;
564 }
unsigned int stop_flag
Definition: uv.h:1793

References loop, and uv_loop_s::stop_flag.

Referenced by idle_cb().

◆ uv_strerror()

const char* uv_strerror ( int  err)

Definition at line 212 of file uv-common.c.

212  {
213  switch (err) {
215  }
216  return uv__unknown_err_code(err);
217 }
#define UV_STRERROR_GEN(name, msg)
Definition: uv-common.c:211

References err, uv__unknown_err_code(), UV_ERRNO_MAP, and UV_STRERROR_GEN.

Referenced by echo_write(), invoke_cgi_script(), main(), on_new_connection(), on_open(), on_read(), on_send(), on_type(), and on_write().

◆ uv_strerror_r()

char* uv_strerror_r ( int  err,
char *  buf,
size_t  buflen 
)

Definition at line 201 of file uv-common.c.

201  {
202  switch (err) {
204  default: snprintf(buf, buflen, "Unknown system error %d", err);
205  }
206  return buf;
207 }
#define UV_STRERROR_GEN_R(name, msg)
Definition: uv-common.c:198

References buflen, err, snprintf, UV_ERRNO_MAP, and UV_STRERROR_GEN_R.

◆ uv_tcp_bind()

int uv_tcp_bind ( uv_tcp_t handle,
const struct sockaddr addr,
unsigned int  flags 
)

Definition at line 277 of file uv-common.c.

279  {
280  unsigned int addrlen;
281 
282  if (handle->type != UV_TCP)
283  return UV_EINVAL;
284 
285  if (addr->sa_family == AF_INET)
286  addrlen = sizeof(struct sockaddr_in);
287  else if (addr->sa_family == AF_INET6)
288  addrlen = sizeof(struct sockaddr_in6);
289  else
290  return UV_EINVAL;
291 
292  return uv__tcp_bind(handle, addr, addrlen, flags);
293 }
int uv__tcp_bind(uv_tcp_t *tcp, const struct sockaddr *addr, unsigned int addrlen, unsigned int flags)
Definition: tcp.c:148

References addr, addrlen, AF_INET, AF_INET6, flags, handle, and uv__tcp_bind().

Referenced by main().

◆ uv_tcp_connect()

int uv_tcp_connect ( uv_connect_t req,
uv_tcp_t handle,
const struct sockaddr addr,
uv_connect_cb  cb 
)

Definition at line 345 of file uv-common.c.

348  {
349  unsigned int addrlen;
350 
351  if (handle->type != UV_TCP)
352  return UV_EINVAL;
353 
354  if (addr->sa_family == AF_INET)
355  addrlen = sizeof(struct sockaddr_in);
356  else if (addr->sa_family == AF_INET6)
357  addrlen = sizeof(struct sockaddr_in6);
358  else
359  return UV_EINVAL;
360 
361  return uv__tcp_connect(req, handle, addr, addrlen, cb);
362 }
int uv__tcp_connect(uv_connect_t *req, uv_tcp_t *handle, const struct sockaddr *addr, unsigned int addrlen, uv_connect_cb cb)
Definition: tcp.c:204
static const char * cb[]
Definition: z80_tab.h:176

References addr, addrlen, AF_INET, AF_INET6, cb, handle, req, and uv__tcp_connect().

Referenced by on_resolved().

◆ uv_udp_bind()

int uv_udp_bind ( uv_udp_t handle,
const struct sockaddr addr,
unsigned int  flags 
)

Definition at line 326 of file uv-common.c.

328  {
329  unsigned int addrlen;
330 
331  if (handle->type != UV_UDP)
332  return UV_EINVAL;
333 
334  if (addr->sa_family == AF_INET)
335  addrlen = sizeof(struct sockaddr_in);
336  else if (addr->sa_family == AF_INET6)
337  addrlen = sizeof(struct sockaddr_in6);
338  else
339  return UV_EINVAL;
340 
341  return uv__udp_bind(handle, addr, addrlen, flags);
342 }
int uv__udp_bind(uv_udp_t *handle, const struct sockaddr *addr, unsigned int addrlen, unsigned int flags)
Definition: udp.c:508

References addr, addrlen, AF_INET, AF_INET6, flags, handle, and uv__udp_bind().

Referenced by main().

◆ uv_udp_connect()

int uv_udp_connect ( uv_udp_t handle,
const struct sockaddr addr 
)

Definition at line 365 of file uv-common.c.

365  {
366  unsigned int addrlen;
367 
368  if (handle->type != UV_UDP)
369  return UV_EINVAL;
370 
371  /* Disconnect the handle */
372  if (addr == NULL) {
373  if (!(handle->flags & UV_HANDLE_UDP_CONNECTED))
374  return UV_ENOTCONN;
375 
376  return uv__udp_disconnect(handle);
377  }
378 
379  if (addr->sa_family == AF_INET)
380  addrlen = sizeof(struct sockaddr_in);
381  else if (addr->sa_family == AF_INET6)
382  addrlen = sizeof(struct sockaddr_in6);
383  else
384  return UV_EINVAL;
385 
386  if (handle->flags & UV_HANDLE_UDP_CONNECTED)
387  return UV_EISCONN;
388 
390 }
int uv__udp_disconnect(uv_udp_t *handle)
Definition: udp.c:629
int uv__udp_connect(uv_udp_t *handle, const struct sockaddr *addr, unsigned int addrlen)
Definition: udp.c:606

References addr, addrlen, AF_INET, AF_INET6, handle, NULL, uv__udp_connect(), uv__udp_disconnect(), and UV_HANDLE_UDP_CONNECTED.

◆ uv_udp_init()

int uv_udp_init ( uv_loop_t loop,
uv_udp_t handle 
)

Definition at line 321 of file uv-common.c.

321  {
323 }
#define AF_UNSPEC
Definition: sftypes.h:283
int uv_udp_init_ex(uv_loop_t *loop, uv_udp_t *handle, unsigned flags)
Definition: uv-common.c:296

References AF_UNSPEC, handle, loop, and uv_udp_init_ex().

Referenced by main().

◆ uv_udp_init_ex()

int uv_udp_init_ex ( uv_loop_t loop,
uv_udp_t handle,
unsigned  flags 
)

Definition at line 296 of file uv-common.c.

296  {
297  unsigned extra_flags;
298  int domain;
299  int rc;
300 
301  /* Use the lower 8 bits for the domain. */
302  domain = flags & 0xFF;
303  if (domain != AF_INET && domain != AF_INET6 && domain != AF_UNSPEC)
304  return UV_EINVAL;
305 
306  /* Use the higher bits for extra flags. */
307  extra_flags = flags & ~0xFF;
308  if (extra_flags & ~UV_UDP_RECVMMSG)
309  return UV_EINVAL;
310 
312 
313  if (rc == 0)
314  if (extra_flags & UV_UDP_RECVMMSG)
315  handle->flags |= UV_HANDLE_UDP_RECVMMSG;
316 
317  return rc;
318 }
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
int uv__udp_init_ex(uv_loop_t *loop, uv_udp_t *handle, unsigned flags, int domain)
Definition: udp.c:954
@ UV_HANDLE_UDP_RECVMMSG
Definition: uv-common.h:115
@ UV_UDP_RECVMMSG
Definition: uv.h:627

References AF_INET, AF_INET6, AF_UNSPEC, domain, flags, handle, loop, uv__udp_init_ex(), UV_HANDLE_UDP_RECVMMSG, and UV_UDP_RECVMMSG.

Referenced by uv_udp_init().

◆ uv_udp_recv_start()

int uv_udp_recv_start ( uv_udp_t handle,
uv_alloc_cb  alloc_cb,
uv_udp_recv_cb  recv_cb 
)

Definition at line 468 of file uv-common.c.

470  {
471  if (handle->type != UV_UDP || alloc_cb == NULL || recv_cb == NULL)
472  return UV_EINVAL;
473  else
474  return uv__udp_recv_start(handle, alloc_cb, recv_cb);
475 }
int uv__udp_recv_start(uv_udp_t *handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
Definition: udp.c:1297

References handle, NULL, and uv__udp_recv_start().

Referenced by main().

◆ uv_udp_recv_stop()

int uv_udp_recv_stop ( uv_udp_t handle)

Definition at line 478 of file uv-common.c.

478  {
479  if (handle->type != UV_UDP)
480  return UV_EINVAL;
481  else
482  return uv__udp_recv_stop(handle);
483 }
int uv__udp_recv_stop(uv_udp_t *handle)
Definition: udp.c:1322

References handle, and uv__udp_recv_stop().

Referenced by on_read(), uv_process_udp_recv_req(), and uv_udp_close().

◆ uv_udp_send()

int uv_udp_send ( uv_udp_send_t req,
uv_udp_t handle,
const uv_buf_t  bufs[],
unsigned int  nbufs,
const struct sockaddr addr,
uv_udp_send_cb  send_cb 
)

Definition at line 438 of file uv-common.c.

443  {
444  int addrlen;
445 
447  if (addrlen < 0)
448  return addrlen;
449 
450  return uv__udp_send(req, handle, bufs, nbufs, addr, addrlen, send_cb);
451 }
int uv__udp_send(uv_udp_send_t *req, uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr, unsigned int addrlen, uv_udp_send_cb send_cb)
Definition: udp.c:650
int uv__udp_check_before_send(uv_udp_t *handle, const struct sockaddr *addr)
Definition: uv-common.c:407

References addr, addrlen, bufs, handle, req, uv__udp_check_before_send(), and uv__udp_send().

Referenced by main().

◆ uv_udp_try_send()

int uv_udp_try_send ( uv_udp_t handle,
const uv_buf_t  bufs[],
unsigned int  nbufs,
const struct sockaddr addr 
)

Definition at line 454 of file uv-common.c.

457  {
458  int addrlen;
459 
461  if (addrlen < 0)
462  return addrlen;
463 
464  return uv__udp_try_send(handle, bufs, nbufs, addr, addrlen);
465 }
int uv__udp_try_send(uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr, unsigned int addrlen)
Definition: udp.c:716

References addr, addrlen, bufs, handle, uv__udp_check_before_send(), and uv__udp_try_send().

◆ uv_unref()

void uv_unref ( uv_handle_t handle)

Definition at line 552 of file uv-common.c.

552  {
554 }
#define uv__handle_unref(h)
Definition: uv-common.h:283

References handle, and uv__handle_unref.

Referenced by eof_timer_init(), and main().

◆ uv_walk()

void uv_walk ( uv_loop_t loop,
uv_walk_cb  walk_cb,
void *  arg 
)

Definition at line 486 of file uv-common.c.

486  {
487  QUEUE queue;
488  QUEUE* q;
489  uv_handle_t* h;
490 
492  while (!QUEUE_EMPTY(&queue)) {
493  q = QUEUE_HEAD(&queue);
494  h = QUEUE_DATA(q, uv_handle_t, handle_queue);
495 
496  QUEUE_REMOVE(q);
498 
499  if (h->flags & UV_HANDLE_INTERNAL) continue;
500  walk_cb(h, arg);
501  }
502 }
#define QUEUE_EMPTY(q)
Definition: queue.h:39
#define QUEUE_HEAD(q)
Definition: queue.h:42
#define QUEUE_INSERT_TAIL(h, q)
Definition: queue.h:92
#define QUEUE_MOVE(h, n)
Definition: queue.h:72
#define QUEUE_REMOVE(q)
Definition: queue.h:101
uv_pipe_t queue
Definition: worker.c:9

References h, uv_loop_s::handle_queue, loop, queue, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_INSERT_TAIL, QUEUE_MOVE, QUEUE_REMOVE, and UV_HANDLE_INTERNAL.

Variable Documentation

◆ default_loop_ptr

uv_loop_t* default_loop_ptr
static

Definition at line 760 of file uv-common.c.

Referenced by uv_default_loop(), uv_loop_close(), and uv_loop_delete().

◆ default_loop_struct

uv_loop_t default_loop_struct
static

Definition at line 759 of file uv-common.c.

Referenced by uv_default_loop().

◆ uv__allocator

uv__allocator_t uv__allocator
static
Initial value:
= {
}
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
void * malloc(size_t size)
Definition: malloc.c:123
void * calloc(size_t number, size_t size)
Definition: malloc.c:102

Definition at line 48 of file uv-common.c.

Referenced by uv__calloc(), uv__free(), uv__malloc(), uv__realloc(), and uv_replace_allocator().