Rizin
unix-like reverse engineering framework and cli tools
internal.h File Reference
#include "uv.h"
#include "../uv-common.h"
#include "uv/tree.h"
#include "winapi.h"
#include "winsock.h"

Go to the source code of this file.

Classes

struct  uv__ipc_socket_xfer_info_t
 

Macros

#define INLINE   inline
 
#define UV_THREAD_LOCAL   __thread
 
#define UV_BEGIN_DISABLE_CRT_ASSERT()
 
#define UV_END_DISABLE_CRT_ASSERT()
 

Typedefs

typedef int(WINAPI * uv__peersockfunc) (SOCKET, struct sockaddr *, int *)
 

Enumerations

enum  uv__ipc_socket_xfer_type_t { UV__IPC_SOCKET_XFER_NONE = 0 , UV__IPC_SOCKET_XFER_TCP_CONNECTION , UV__IPC_SOCKET_XFER_TCP_SERVER }
 

Functions

int uv_tcp_listen (uv_tcp_t *handle, int backlog, uv_connection_cb cb)
 
int uv_tcp_accept (uv_tcp_t *server, uv_tcp_t *client)
 
int uv_tcp_read_start (uv_tcp_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
 
int uv_tcp_write (uv_loop_t *loop, uv_write_t *req, uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
 
int uv__tcp_try_write (uv_tcp_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
 
void uv_process_tcp_read_req (uv_loop_t *loop, uv_tcp_t *handle, uv_req_t *req)
 
void uv_process_tcp_write_req (uv_loop_t *loop, uv_tcp_t *handle, uv_write_t *req)
 
void uv_process_tcp_accept_req (uv_loop_t *loop, uv_tcp_t *handle, uv_req_t *req)
 
void uv_process_tcp_connect_req (uv_loop_t *loop, uv_tcp_t *handle, uv_connect_t *req)
 
void uv_tcp_close (uv_loop_t *loop, uv_tcp_t *tcp)
 
void uv_tcp_endgame (uv_loop_t *loop, uv_tcp_t *handle)
 
int uv__tcp_xfer_export (uv_tcp_t *handle, int pid, uv__ipc_socket_xfer_type_t *xfer_type, uv__ipc_socket_xfer_info_t *xfer_info)
 
int uv__tcp_xfer_import (uv_tcp_t *tcp, uv__ipc_socket_xfer_type_t xfer_type, uv__ipc_socket_xfer_info_t *xfer_info)
 
void uv_process_udp_recv_req (uv_loop_t *loop, uv_udp_t *handle, uv_req_t *req)
 
void uv_process_udp_send_req (uv_loop_t *loop, uv_udp_t *handle, uv_udp_send_t *req)
 
void uv_udp_close (uv_loop_t *loop, uv_udp_t *handle)
 
void uv_udp_endgame (uv_loop_t *loop, uv_udp_t *handle)
 
int uv_stdio_pipe_server (uv_loop_t *loop, uv_pipe_t *handle, DWORD access, char *name, size_t nameSize)
 
int uv_pipe_listen (uv_pipe_t *handle, int backlog, uv_connection_cb cb)
 
int uv_pipe_accept (uv_pipe_t *server, uv_stream_t *client)
 
int uv_pipe_read_start (uv_pipe_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
 
void uv__pipe_read_stop (uv_pipe_t *handle)
 
int uv__pipe_write (uv_loop_t *loop, uv_write_t *req, uv_pipe_t *handle, const uv_buf_t bufs[], size_t nbufs, uv_stream_t *send_handle, uv_write_cb cb)
 
void uv_process_pipe_read_req (uv_loop_t *loop, uv_pipe_t *handle, uv_req_t *req)
 
void uv_process_pipe_write_req (uv_loop_t *loop, uv_pipe_t *handle, uv_write_t *req)
 
void uv_process_pipe_accept_req (uv_loop_t *loop, uv_pipe_t *handle, uv_req_t *raw_req)
 
void uv_process_pipe_connect_req (uv_loop_t *loop, uv_pipe_t *handle, uv_connect_t *req)
 
void uv_process_pipe_shutdown_req (uv_loop_t *loop, uv_pipe_t *handle, uv_shutdown_t *req)
 
void uv_pipe_close (uv_loop_t *loop, uv_pipe_t *handle)
 
void uv_pipe_cleanup (uv_loop_t *loop, uv_pipe_t *handle)
 
void uv_pipe_endgame (uv_loop_t *loop, uv_pipe_t *handle)
 
void uv_console_init (void)
 
int uv_tty_read_start (uv_tty_t *handle, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
 
int uv_tty_read_stop (uv_tty_t *handle)
 
int uv_tty_write (uv_loop_t *loop, uv_write_t *req, uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
 
int uv__tty_try_write (uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs)
 
void uv_tty_close (uv_tty_t *handle)
 
void uv_process_tty_read_req (uv_loop_t *loop, uv_tty_t *handle, uv_req_t *req)
 
void uv_process_tty_write_req (uv_loop_t *loop, uv_tty_t *handle, uv_write_t *req)
 
void uv_process_tty_accept_req (uv_loop_t *loop, uv_tty_t *handle, uv_req_t *raw_req)
 
void uv_process_tty_connect_req (uv_loop_t *loop, uv_tty_t *handle, uv_connect_t *req)
 
void uv_tty_endgame (uv_loop_t *loop, uv_tty_t *handle)
 
void uv_process_poll_req (uv_loop_t *loop, uv_poll_t *handle, uv_req_t *req)
 
int uv_poll_close (uv_loop_t *loop, uv_poll_t *handle)
 
void uv_poll_endgame (uv_loop_t *loop, uv_poll_t *handle)
 
void uv_loop_watcher_endgame (uv_loop_t *loop, uv_handle_t *handle)
 
void uv_prepare_invoke (uv_loop_t *loop)
 
void uv_check_invoke (uv_loop_t *loop)
 
void uv_idle_invoke (uv_loop_t *loop)
 
void uv__once_init (void)
 
void uv_async_close (uv_loop_t *loop, uv_async_t *handle)
 
void uv_async_endgame (uv_loop_t *loop, uv_async_t *handle)
 
void uv_process_async_wakeup_req (uv_loop_t *loop, uv_async_t *handle, uv_req_t *req)
 
void uv_signals_init (void)
 
int uv__signal_dispatch (int signum)
 
void uv_signal_close (uv_loop_t *loop, uv_signal_t *handle)
 
void uv_signal_endgame (uv_loop_t *loop, uv_signal_t *handle)
 
void uv_process_signal_req (uv_loop_t *loop, uv_signal_t *handle, uv_req_t *req)
 
void uv_process_proc_exit (uv_loop_t *loop, uv_process_t *handle)
 
void uv_process_close (uv_loop_t *loop, uv_process_t *handle)
 
void uv_process_endgame (uv_loop_t *loop, uv_process_t *handle)
 
int uv_translate_sys_error (int sys_errno)
 
void uv_fs_init (void)
 
void uv_process_fs_event_req (uv_loop_t *loop, uv_req_t *req, uv_fs_event_t *handle)
 
void uv_fs_event_close (uv_loop_t *loop, uv_fs_event_t *handle)
 
void uv_fs_event_endgame (uv_loop_t *loop, uv_fs_event_t *handle)
 
void uv__fs_poll_endgame (uv_loop_t *loop, uv_fs_poll_t *handle)
 
void uv__util_init (void)
 
uint64_t uv__hrtime (unsigned int scale)
 
 __declspec (noreturn) void uv_fatal_error(const int errorno
 
int uv__getpwuid_r (uv_passwd_t *pwd)
 
int uv__convert_utf16_to_utf8 (const WCHAR *utf16, int utf16len, char **utf8)
 
int uv__convert_utf8_to_utf16 (const char *utf8, int utf8len, WCHAR **utf16)
 
int uv__getsockpeername (const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen, int delayed_error)
 
int uv__random_rtlgenrandom (void *buf, size_t buflen)
 
int uv__stdio_create (uv_loop_t *loop, const uv_process_options_t *options, BYTE **buffer_ptr)
 
void uv__stdio_destroy (BYTE *buffer)
 
void uv__stdio_noinherit (BYTE *buffer)
 
int uv__stdio_verify (BYTE *buffer, WORD size)
 
WORD uv__stdio_size (BYTE *buffer)
 
HANDLE uv__stdio_handle (BYTE *buffer, int fd)
 
void uv_winapi_init (void)
 
void uv_winsock_init (void)
 
int uv_ntstatus_to_winsock_error (NTSTATUS status)
 
BOOL uv_get_acceptex_function (SOCKET socket, LPFN_ACCEPTEX *target)
 
BOOL uv_get_connectex_function (SOCKET socket, LPFN_CONNECTEX *target)
 
int WSAAPI uv_wsarecv_workaround (SOCKET socket, WSABUF *buffers, DWORD buffer_count, DWORD *bytes, DWORD *flags, WSAOVERLAPPED *overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine)
 
int WSAAPI uv_wsarecvfrom_workaround (SOCKET socket, WSABUF *buffers, DWORD buffer_count, DWORD *bytes, DWORD *flags, struct sockaddr *addr, int *addr_len, WSAOVERLAPPED *overlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE completion_routine)
 
int WSAAPI uv_msafd_poll (SOCKET socket, AFD_POLL_INFO *info_in, AFD_POLL_INFO *info_out, OVERLAPPED *overlapped)
 
void uv__wake_all_loops (void)
 
void uv__init_detect_system_wakeup (void)
 

Variables

const char * syscall
 
int uv_tcp_non_ifs_lsp_ipv4
 
int uv_tcp_non_ifs_lsp_ipv6
 
struct sockaddr_in uv_addr_ip4_any_
 
struct sockaddr_in6 uv_addr_ip6_any_
 

Macro Definition Documentation

◆ INLINE

#define INLINE   inline

Definition at line 36 of file internal.h.

◆ UV_BEGIN_DISABLE_CRT_ASSERT

#define UV_BEGIN_DISABLE_CRT_ASSERT ( )

Definition at line 56 of file internal.h.

◆ UV_END_DISABLE_CRT_ASSERT

#define UV_END_DISABLE_CRT_ASSERT ( )

Definition at line 57 of file internal.h.

◆ UV_THREAD_LOCAL

#define UV_THREAD_LOCAL   __thread

Definition at line 37 of file internal.h.

Typedef Documentation

◆ uv__peersockfunc

typedef int(WINAPI * uv__peersockfunc) (SOCKET, struct sockaddr *, int *)

Definition at line 275 of file internal.h.

Enumeration Type Documentation

◆ uv__ipc_socket_xfer_type_t

Enumerator
UV__IPC_SOCKET_XFER_NONE 
UV__IPC_SOCKET_XFER_TCP_CONNECTION 
UV__IPC_SOCKET_XFER_TCP_SERVER 

Definition at line 64 of file internal.h.

64  {
uv__ipc_socket_xfer_type_t
Definition: internal.h:64
@ UV__IPC_SOCKET_XFER_NONE
Definition: internal.h:65
@ UV__IPC_SOCKET_XFER_TCP_CONNECTION
Definition: internal.h:66
@ UV__IPC_SOCKET_XFER_TCP_SERVER
Definition: internal.h:67

Function Documentation

◆ __declspec()

__declspec ( noreturn  ) const

Referenced by fs__scandir().

◆ uv__convert_utf16_to_utf8()

int uv__convert_utf16_to_utf8 ( const WCHAR *  utf16,
int  utf16len,
char **  utf8 
)

Definition at line 1280 of file util.c.

1280  {
1281  DWORD bufsize;
1282 
1283  if (utf16 == NULL)
1284  return UV_EINVAL;
1285 
1286  /* Check how much space we need */
1287  bufsize = WideCharToMultiByte(CP_UTF8,
1288  0,
1289  utf16,
1290  utf16len,
1291  NULL,
1292  0,
1293  NULL,
1294  NULL);
1295 
1296  if (bufsize == 0)
1297  return uv_translate_sys_error(GetLastError());
1298 
1299  /* Allocate the destination buffer adding an extra byte for the terminating
1300  * NULL. If utf16len is not -1 WideCharToMultiByte will not add it, so
1301  * we do it ourselves always, just in case. */
1302  *utf8 = uv__malloc(bufsize + 1);
1303 
1304  if (*utf8 == NULL)
1305  return UV_ENOMEM;
1306 
1307  /* Convert to UTF-8 */
1308  bufsize = WideCharToMultiByte(CP_UTF8,
1309  0,
1310  utf16,
1311  utf16len,
1312  *utf8,
1313  bufsize,
1314  NULL,
1315  NULL);
1316 
1317  if (bufsize == 0) {
1318  uv__free(*utf8);
1319  *utf8 = NULL;
1320  return uv_translate_sys_error(GetLastError());
1321  }
1322 
1323  (*utf8)[bufsize] = '\0';
1324  return 0;
1325 }
#define NULL
Definition: cris-opc.c:27
void * uv__malloc(size_t size)
Definition: uv-common.c:75
void uv__free(void *ptr)
Definition: uv-common.c:81
UV_EXTERN int uv_translate_sys_error(int sys_errno)
Definition: core.c:1249
DWORD

References DWORD, NULL, uv__free(), uv__malloc(), and uv_translate_sys_error().

Referenced by fs__readdir(), uv__get_process_title(), uv__getpwuid_r(), uv_cpu_info(), uv_os_environ(), and uv_process_fs_event_req().

◆ uv__convert_utf8_to_utf16()

int uv__convert_utf8_to_utf16 ( const char *  utf8,
int  utf8len,
WCHAR **  utf16 
)

Definition at line 1335 of file util.c.

1335  {
1336  int bufsize;
1337 
1338  if (utf8 == NULL)
1339  return UV_EINVAL;
1340 
1341  /* Check how much space we need */
1342  bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, NULL, 0);
1343 
1344  if (bufsize == 0)
1345  return uv_translate_sys_error(GetLastError());
1346 
1347  /* Allocate the destination buffer adding an extra byte for the terminating
1348  * NULL. If utf8len is not -1 MultiByteToWideChar will not add it, so
1349  * we do it ourselves always, just in case. */
1350  *utf16 = uv__malloc(sizeof(WCHAR) * (bufsize + 1));
1351 
1352  if (*utf16 == NULL)
1353  return UV_ENOMEM;
1354 
1355  /* Convert to UTF-16 */
1356  bufsize = MultiByteToWideChar(CP_UTF8, 0, utf8, utf8len, *utf16, bufsize);
1357 
1358  if (bufsize == 0) {
1359  uv__free(*utf16);
1360  *utf16 = NULL;
1361  return uv_translate_sys_error(GetLastError());
1362  }
1363 
1364  (*utf16)[bufsize] = L'\0';
1365  return 0;
1366 }
#define L
Definition: zip_err_str.c:7

References L, NULL, uv__free(), uv__malloc(), and uv_translate_sys_error().

Referenced by uv_os_getenv(), uv_os_setenv(), and uv_os_unsetenv().

◆ uv__fs_poll_endgame()

void uv__fs_poll_endgame ( uv_loop_t loop,
uv_fs_poll_t handle 
)

Referenced by uv_process_endgames().

◆ 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 }
#define r
Definition: crypto_rc6.c:12
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

References ARRAY_SIZE, buf, DWORD, ERANGE, uv_passwd_s::gid, HANDLE, uv_passwd_s::homedir, memcpy(), NULL, path, r, uv_passwd_s::shell, uv_passwd_s::uid, UNLEN, uv_passwd_s::username, uv__convert_utf16_to_utf8(), uv__free(), uv__malloc(), and uv_translate_sys_error().

Referenced by uv_os_get_passwd(), and uv_os_homedir().

◆ uv__getsockpeername()

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

Definition at line 727 of file core.c.

731  {
732 
733  int result;
734  uv_os_fd_t fd;
735 
736  result = uv_fileno(handle, &fd);
737  if (result != 0)
738  return result;
739 
740  if (delayed_error)
741  return uv_translate_sys_error(delayed_error);
742 
743  result = func((SOCKET) fd, name, namelen);
744  if (result != 0)
745  return uv_translate_sys_error(WSAGetLastError());
746 
747  return 0;
748 }
static mcore_handle handle
Definition: asm_mcore.c:8
Definition: z80asm.h:102
int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
Definition: core.c:767
int uv_translate_sys_error(int sys_errno)
Definition: core.c:1249
int uv_os_fd_t
Definition: unix.h:130
static const z80_opcode fd[]
Definition: z80_tab.h:997

References fd, handle, uv_fileno(), and uv_translate_sys_error().

◆ uv__hrtime()

uint64_t uv__hrtime ( unsigned int  scale)

Definition at line 495 of file util.c.

495  {
496  LARGE_INTEGER counter;
497  double scaled_freq;
498  double result;
499 
501  assert(scale != 0);
502  if (!QueryPerformanceCounter(&counter)) {
503  uv_fatal_error(GetLastError(), "QueryPerformanceCounter");
504  }
505  assert(counter.QuadPart != 0);
506 
507  /* Because we have no guarantee about the order of magnitude of the
508  * performance counter interval, integer math could cause this computation
509  * to overflow. Therefore we resort to floating point math.
510  */
511  scaled_freq = (double) hrtime_frequency_ / scale;
512  result = (double) counter.QuadPart / scaled_freq;
513  return (uint64_t) result;
514 }
void uv_fatal_error(const int errorno, const char *syscall)
Definition: error.c:35
assert(limit<=UINT32_MAX/2)
unsigned long uint64_t
Definition: sftypes.h:28
int64_t counter
Definition: main.c:4
static uint64_t hrtime_frequency_
Definition: util.c:73

References assert(), counter, hrtime_frequency_, and uv_fatal_error().

Referenced by uv_hrtime().

◆ uv__init_detect_system_wakeup()

void uv__init_detect_system_wakeup ( void  )

Definition at line 28 of file detect-wakeup.c.

28  {
29  /* Try registering system power event callback. This is the cleanest
30  * method, but it will only work on Win8 and above.
31  */
33 }
static void uv__register_system_resume_callback(void)
Definition: detect-wakeup.c:44

References uv__register_system_resume_callback().

Referenced by uv_init().

◆ uv__once_init()

void uv__once_init ( void  )

Definition at line 329 of file core.c.

329  {
331 }
static void uv_init(void)
Definition: core.c:176
static uv_once_t uv_init_guard_
Definition: core.c:40
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419

References uv_init(), uv_init_guard_, and uv_once().

Referenced by uv__pipe_getname(), uv__random(), uv_cpu_info(), uv_fs_req_init(), uv_get_process_title(), uv_hrtime(), uv_loop_init(), uv_os_gethostname(), uv_os_uname(), uv_pipe_open(), uv_set_process_title(), and uv_tty_init().

◆ uv__pipe_read_stop()

void uv__pipe_read_stop ( uv_pipe_t handle)

Definition at line 775 of file pipe.c.

775  {
776  handle->flags &= ~UV_HANDLE_READING;
778 
780 }
#define DECREASE_ACTIVE_COUNT(loop, handle)
Definition: handle-inl.h:32
void uv__pipe_interrupt_read(uv_pipe_t *handle)
Definition: pipe.c:728
@ UV_HANDLE_READING
Definition: uv-common.h:90

References DECREASE_ACTIVE_COUNT, handle, uv__pipe_interrupt_read(), and UV_HANDLE_READING.

Referenced by uv_read_stop().

◆ uv__pipe_write()

int uv__pipe_write ( uv_loop_t loop,
uv_write_t req,
uv_pipe_t handle,
const uv_buf_t  bufs[],
size_t  nbufs,
uv_stream_t send_handle,
uv_write_cb  cb 
)

Definition at line 1578 of file pipe.c.

1584  {
1585  if (handle->ipc) {
1586  /* IPC pipe write: use framing protocol. */
1587  return uv__pipe_write_ipc(loop, req, handle, bufs, nbufs, send_handle, cb);
1588  } else {
1589  /* Non-IPC pipe write: put data on the wire directly. */
1590  assert(send_handle == NULL);
1591  return uv__pipe_write_data(loop, req, handle, bufs, nbufs, cb, 0);
1592  }
1593 }
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
uv_loop_t * loop
Definition: main.c:7
static int uv__pipe_write_data(uv_loop_t *loop, uv_write_t *req, uv_pipe_t *handle, const uv_buf_t bufs[], size_t nbufs, uv_write_cb cb, int copy_always)
Definition: pipe.c:1312
int uv__pipe_write_ipc(uv_loop_t *loop, uv_write_t *req, uv_pipe_t *handle, const uv_buf_t data_bufs[], size_t data_buf_count, uv_stream_t *send_handle, uv_write_cb cb)
Definition: pipe.c:1476
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
Definition: util.c:18
static const char * cb[]
Definition: z80_tab.h:176

References assert(), bufs, cb, handle, loop, NULL, req, uv__pipe_write_data(), and uv__pipe_write_ipc().

Referenced by uv_write(), and uv_write2().

◆ uv__random_rtlgenrandom()

int uv__random_rtlgenrandom ( void *  buf,
size_t  buflen 
)

Definition at line 1965 of file util.c.

1965  {
1966  if (buflen == 0)
1967  return 0;
1968 
1969  if (SystemFunction036(buf, buflen) == FALSE)
1970  return UV_EIO;
1971 
1972  return 0;
1973 }
#define FALSE
Definition: mybfd.h:102
BOOLEAN NTAPI SystemFunction036(PVOID Buffer, ULONG BufferLength)
ut64 buflen
Definition: core.c:76

References buflen, FALSE, and SystemFunction036().

Referenced by fs__mktemp(), and uv__random().

◆ uv__signal_dispatch()

int uv__signal_dispatch ( int  signum)

Definition at line 80 of file signal.c.

80  {
81  uv_signal_t lookup;
83  int dispatched;
84 
85  dispatched = 0;
86 
87  EnterCriticalSection(&uv__signal_lock);
88 
89  lookup.signum = signum;
90  lookup.loop = NULL;
91 
92  for (handle = RB_NFIND(uv_signal_tree_s, &uv__signal_tree, &lookup);
93  handle != NULL && handle->signum == signum;
94  handle = RB_NEXT(uv_signal_tree_s, &uv__signal_tree, handle)) {
95  unsigned long previous = InterlockedExchange(
96  (volatile LONG*) &handle->pending_signum, signum);
97 
99  continue;
100 
101  if (!previous) {
102  POST_COMPLETION_FOR_REQ(handle->loop, &handle->signal_req);
103  }
104 
105  dispatched = 1;
106  if (handle->flags & UV_SIGNAL_ONE_SHOT)
108  }
109 
110  LeaveCriticalSection(&uv__signal_lock);
111 
112  return dispatched;
113 }
#define LONG
InterlockedExchange
Definition: kernel.h:57
#define RB_NEXT(name, x, y)
Definition: tree.h:731
#define RB_NFIND(name, x, y)
Definition: tree.h:730
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 signum
Definition: sflib.h:79
#define POST_COMPLETION_FOR_REQ(loop, req)
Definition: req-inl.h:76
int signum
Definition: uv.h:1577
static CRITICAL_SECTION uv__signal_lock
Definition: signal.c:33
static struct uv_signal_tree_s uv__signal_tree
Definition: signal.c:32
@ UV_SIGNAL_ONE_SHOT
Definition: uv-common.h:129
@ UV_SIGNAL_ONE_SHOT_DISPATCHED
Definition: uv-common.h:128

References handle, InterlockedExchange, LONG, NULL, POST_COMPLETION_FOR_REQ, RB_NEXT, RB_NFIND, signum, uv_signal_s::signum, uv__signal_lock, uv__signal_tree, UV_SIGNAL_ONE_SHOT, and UV_SIGNAL_ONE_SHOT_DISPATCHED.

Referenced by uv__signal_control_handler(), and uv__tty_console_signal_resize().

◆ uv__stdio_create()

int uv__stdio_create ( uv_loop_t loop,
const uv_process_options_t options,
BYTE **  buffer_ptr 
)

Definition at line 265 of file process-stdio.c.

267  {
268  BYTE* buffer;
269  int count, i;
270  int err;
271 
272  count = options->stdio_count;
273 
274  if (count < 0 || count > 255) {
275  /* Only support FDs 0-255 */
276  return ERROR_NOT_SUPPORTED;
277  } else if (count < 3) {
278  /* There should always be at least 3 stdio handles. */
279  count = 3;
280  }
281 
282  /* Allocate the child stdio buffer */
284  if (buffer == NULL) {
285  return ERROR_OUTOFMEMORY;
286  }
287 
288  /* Prepopulate the buffer with INVALID_HANDLE_VALUE handles so we can clean
289  * up on failure. */
291  for (i = 0; i < count; i++) {
294  }
295 
296  for (i = 0; i < count; i++) {
297  uv_stdio_container_t fdopt;
298  if (i < options->stdio_count) {
299  fdopt = options->stdio[i];
300  } else {
301  fdopt.flags = UV_IGNORE;
302  }
303 
304  switch (fdopt.flags & (UV_IGNORE | UV_CREATE_PIPE | UV_INHERIT_FD |
306  case UV_IGNORE:
307  /* Starting a process with no stdin/stout/stderr can confuse it. So no
308  * matter what the user specified, we make sure the first three FDs are
309  * always open in their typical modes, e. g. stdin be readable and
310  * stdout/err should be writable. For FDs > 2, don't do anything - all
311  * handles in the stdio buffer are initialized with.
312  * INVALID_HANDLE_VALUE, which should be okay. */
313  if (i <= 2) {
314  DWORD access = (i == 0) ? FILE_GENERIC_READ :
315  FILE_GENERIC_WRITE | FILE_READ_ATTRIBUTES;
316 
318  access);
319  if (err)
320  goto error;
321 
323  }
324  break;
325 
326  case UV_CREATE_PIPE: {
327  /* Create a pair of two connected pipe ends; one end is turned into an
328  * uv_pipe_t for use by the parent. The other one is given to the
329  * child. */
330  uv_pipe_t* parent_pipe = (uv_pipe_t*) fdopt.data.stream;
331  HANDLE child_pipe = INVALID_HANDLE_VALUE;
332 
333  /* Create a new, connected pipe pair. stdio[i]. stream should point to
334  * an uninitialized, but not connected pipe handle. */
335  assert(fdopt.data.stream->type == UV_NAMED_PIPE);
336  assert(!(fdopt.data.stream->flags & UV_HANDLE_CONNECTION));
337  assert(!(fdopt.data.stream->flags & UV_HANDLE_PIPESERVER));
338 
340  parent_pipe,
341  &child_pipe,
342  fdopt.flags);
343  if (err)
344  goto error;
345 
346  CHILD_STDIO_HANDLE(buffer, i) = child_pipe;
348  break;
349  }
350 
351  case UV_INHERIT_FD: {
352  /* Inherit a raw FD. */
353  HANDLE child_handle;
354 
355  /* Make an inheritable duplicate of the handle. */
356  err = uv__duplicate_fd(loop, fdopt.data.fd, &child_handle);
357  if (err) {
358  /* If fdopt. data. fd is not valid and fd <= 2, then ignore the
359  * error. */
360  if (fdopt.data.fd <= 2 && err == ERROR_INVALID_HANDLE) {
363  break;
364  }
365  goto error;
366  }
367 
368  /* Figure out what the type is. */
369  switch (GetFileType(child_handle)) {
370  case FILE_TYPE_DISK:
372  break;
373 
374  case FILE_TYPE_PIPE:
376  break;
377 
378  case FILE_TYPE_CHAR:
379  case FILE_TYPE_REMOTE:
381  break;
382 
383  case FILE_TYPE_UNKNOWN:
384  if (GetLastError() != 0) {
385  err = GetLastError();
386  CloseHandle(child_handle);
387  goto error;
388  }
390  break;
391 
392  default:
393  assert(0);
394  return -1;
395  }
396 
397  CHILD_STDIO_HANDLE(buffer, i) = child_handle;
398  break;
399  }
400 
401  case UV_INHERIT_STREAM: {
402  /* Use an existing stream as the stdio handle for the child. */
403  HANDLE stream_handle, child_handle;
404  unsigned char crt_flags;
405  uv_stream_t* stream = fdopt.data.stream;
406 
407  /* Leech the handle out of the stream. */
408  if (stream->type == UV_TTY) {
409  stream_handle = ((uv_tty_t*) stream)->handle;
410  crt_flags = FOPEN | FDEV;
411  } else if (stream->type == UV_NAMED_PIPE &&
412  stream->flags & UV_HANDLE_CONNECTION) {
413  stream_handle = ((uv_pipe_t*) stream)->handle;
414  crt_flags = FOPEN | FPIPE;
415  } else {
416  stream_handle = INVALID_HANDLE_VALUE;
417  crt_flags = 0;
418  }
419 
420  if (stream_handle == NULL ||
421  stream_handle == INVALID_HANDLE_VALUE) {
422  /* The handle is already closed, or not yet created, or the stream
423  * type is not supported. */
424  err = ERROR_NOT_SUPPORTED;
425  goto error;
426  }
427 
428  /* Make an inheritable copy of the handle. */
429  err = uv__duplicate_handle(loop, stream_handle, &child_handle);
430  if (err)
431  goto error;
432 
433  CHILD_STDIO_HANDLE(buffer, i) = child_handle;
434  CHILD_STDIO_CRT_FLAGS(buffer, i) = crt_flags;
435  break;
436  }
437 
438  default:
439  assert(0);
440  return -1;
441  }
442  }
443 
444  *buffer_ptr = buffer;
445  return 0;
446 
447  error:
449  return err;
450 }
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
struct buffer buffer
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 stream
Definition: ioapi.h:138
#define INVALID_HANDLE_VALUE
Definition: iowin32.c:21
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
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
unsigned char BYTE
Definition: lz4.c:286
static int uv__create_stdio_pipe_pair(uv_loop_t *loop, uv_pipe_t *server_pipe, HANDLE *child_pipe_ptr, unsigned int flags)
Definition: process-stdio.c:98
#define CHILD_STDIO_CRT_FLAGS(buffer, fd)
Definition: process-stdio.c:46
static int uv__duplicate_handle(uv_loop_t *loop, HANDLE handle, HANDLE *dup)
void uv__stdio_destroy(BYTE *buffer)
static int uv__duplicate_fd(uv_loop_t *loop, int fd, HANDLE *dup)
#define FPIPE
Definition: process-stdio.c:61
#define FOPEN
Definition: process-stdio.c:58
#define FDEV
Definition: process-stdio.c:64
int uv__create_nul_handle(HANDLE *handle_ptr, DWORD access)
#define CHILD_STDIO_COUNT(buffer)
Definition: process-stdio.c:43
#define CHILD_STDIO_HANDLE(buffer, fd)
Definition: process-stdio.c:49
#define CHILD_STDIO_SIZE(count)
Definition: process-stdio.c:38
Definition: buffer.h:15
Definition: uv.h:767
uv_stream_t * stream
Definition: uv.h:946
uv_stdio_flags flags
Definition: uv.h:943
union uv_stdio_container_s::@397 data
Definition: uv.h:714
void error(const char *msg)
Definition: untgz.c:593
@ UV_HANDLE_PIPESERVER
Definition: uv-common.h:119
@ UV_HANDLE_CONNECTION
Definition: uv-common.h:83
@ UV_INHERIT_FD
Definition: uv.h:924
@ UV_CREATE_PIPE
Definition: uv.h:923
@ UV_IGNORE
Definition: uv.h:922
@ UV_INHERIT_STREAM
Definition: uv.h:925
DWORD * HANDLE

References access, assert(), CHILD_STDIO_COUNT, CHILD_STDIO_CRT_FLAGS, CHILD_STDIO_HANDLE, CHILD_STDIO_SIZE, count, uv_stdio_container_s::data, DWORD, err, error(), uv_stdio_container_s::fd, FDEV, uv_stdio_container_s::flags, FOPEN, FPIPE, HANDLE, i, INVALID_HANDLE_VALUE, loop, NULL, options, uv_stdio_container_s::stream, uv__create_nul_handle(), uv__create_stdio_pipe_pair(), uv__duplicate_fd(), uv__duplicate_handle(), uv__malloc(), uv__stdio_destroy(), UV_CREATE_PIPE, UV_HANDLE_CONNECTION, UV_HANDLE_PIPESERVER, UV_IGNORE, UV_INHERIT_FD, and UV_INHERIT_STREAM.

Referenced by uv_spawn().

◆ uv__stdio_destroy()

void uv__stdio_destroy ( BYTE buffer)

Definition at line 453 of file process-stdio.c.

453  {
454  int i, count;
455 
457  for (i = 0; i < count; i++) {
459  if (handle != INVALID_HANDLE_VALUE) {
460  CloseHandle(handle);
461  }
462  }
463 
464  uv__free(buffer);
465 }

References CHILD_STDIO_COUNT, CHILD_STDIO_HANDLE, count, handle, HANDLE, i, INVALID_HANDLE_VALUE, and uv__free().

Referenced by uv__stdio_create(), and uv_spawn().

◆ uv__stdio_handle()

HANDLE uv__stdio_handle ( BYTE buffer,
int  fd 
)

Definition at line 510 of file process-stdio.c.

510  {
511  return CHILD_STDIO_HANDLE(buffer, fd);
512 }

References CHILD_STDIO_HANDLE, and fd.

Referenced by uv_spawn().

◆ uv__stdio_noinherit()

void uv__stdio_noinherit ( BYTE buffer)

Definition at line 468 of file process-stdio.c.

468  {
469  int i, count;
470 
472  for (i = 0; i < count; i++) {
474  if (handle != INVALID_HANDLE_VALUE) {
475  SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0);
476  }
477  }
478 }

References CHILD_STDIO_COUNT, CHILD_STDIO_HANDLE, count, handle, HANDLE, i, and INVALID_HANDLE_VALUE.

Referenced by uv_disable_stdio_inheritance().

◆ uv__stdio_size()

WORD uv__stdio_size ( BYTE buffer)

Definition at line 505 of file process-stdio.c.

505  {
506  return (WORD) CHILD_STDIO_SIZE(CHILD_STDIO_COUNT((buffer)));
507 }

References CHILD_STDIO_COUNT, and CHILD_STDIO_SIZE.

Referenced by uv_spawn().

◆ uv__stdio_verify()

int uv__stdio_verify ( BYTE buffer,
WORD  size 
)

Definition at line 481 of file process-stdio.c.

481  {
482  unsigned int count;
483 
484  /* Check the buffer pointer. */
485  if (buffer == NULL)
486  return 0;
487 
488  /* Verify that the buffer is at least big enough to hold the count. */
489  if (size < CHILD_STDIO_SIZE(0))
490  return 0;
491 
492  /* Verify if the count is within range. */
494  if (count > 256)
495  return 0;
496 
497  /* Verify that the buffer size is big enough to hold info for N FDs. */
498  if (size < CHILD_STDIO_SIZE(count))
499  return 0;
500 
501  return 1;
502 }
voidpf void uLong size
Definition: ioapi.h:138

References CHILD_STDIO_COUNT, CHILD_STDIO_SIZE, count, and NULL.

Referenced by uv_disable_stdio_inheritance().

◆ uv__tcp_try_write()

int uv__tcp_try_write ( uv_tcp_t handle,
const uv_buf_t  bufs[],
unsigned int  nbufs 
)

Definition at line 968 of file tcp.c.

970  {
971  int result;
972  DWORD bytes;
973 
974  if (handle->stream.conn.write_reqs_pending > 0)
975  return UV_EAGAIN;
976 
977  result = WSASend(handle->socket,
978  (WSABUF*) bufs,
979  nbufs,
980  &bytes,
981  0,
982  NULL,
983  NULL);
984 
985  if (result == SOCKET_ERROR)
986  return uv_translate_sys_error(WSAGetLastError());
987  else
988  return bytes;
989 }
static ut8 bytes[32]
Definition: asm_arc.c:23

References bufs, bytes, DWORD, handle, NULL, and uv_translate_sys_error().

Referenced by uv_try_write().

◆ uv__tcp_xfer_export()

int uv__tcp_xfer_export ( uv_tcp_t handle,
int  pid,
uv__ipc_socket_xfer_type_t xfer_type,
uv__ipc_socket_xfer_info_t xfer_info 
)

Definition at line 1242 of file tcp.c.

1245  {
1246  if (handle->flags & UV_HANDLE_CONNECTION) {
1248  } else {
1249  *xfer_type = UV__IPC_SOCKET_XFER_TCP_SERVER;
1250  /* We're about to share the socket with another process. Because this is a
1251  * listening socket, we assume that the other process will be accepting
1252  * connections on it. Thus, before sharing the socket with another process,
1253  * we call listen here in the parent process. */
1254  if (!(handle->flags & UV_HANDLE_LISTENING)) {
1255  if (!(handle->flags & UV_HANDLE_BOUND)) {
1256  return ERROR_NOT_SUPPORTED;
1257  }
1258  if (handle->delayed_error == 0 &&
1259  listen(handle->socket, SOMAXCONN) == SOCKET_ERROR) {
1260  handle->delayed_error = WSAGetLastError();
1261  }
1262  }
1263  }
1264 
1265  if (WSADuplicateSocketW(handle->socket, target_pid, &xfer_info->socket_info))
1266  return WSAGetLastError();
1267  xfer_info->delayed_error = handle->delayed_error;
1268 
1269  /* Mark the local copy of the handle as 'shared' so we behave in a way that's
1270  * friendly to the process(es) that we share the socket with. */
1272 
1273  return 0;
1274 }
static struct sockaddr static addrlen listen
Definition: sfsocketcall.h:116
WSAPROTOCOL_INFOW socket_info
Definition: internal.h:71
@ UV_HANDLE_LISTENING
Definition: uv-common.h:82
@ UV_HANDLE_SHARED_TCP_SOCKET
Definition: uv-common.h:110
@ UV_HANDLE_BOUND
Definition: uv-common.h:91

References uv__ipc_socket_xfer_info_t::delayed_error, handle, listen, uv__ipc_socket_xfer_info_t::socket_info, UV__IPC_SOCKET_XFER_TCP_CONNECTION, UV__IPC_SOCKET_XFER_TCP_SERVER, UV_HANDLE_BOUND, UV_HANDLE_CONNECTION, UV_HANDLE_LISTENING, and UV_HANDLE_SHARED_TCP_SOCKET.

Referenced by uv__pipe_write_ipc().

◆ uv__tcp_xfer_import()

int uv__tcp_xfer_import ( uv_tcp_t tcp,
uv__ipc_socket_xfer_type_t  xfer_type,
uv__ipc_socket_xfer_info_t xfer_info 
)

Definition at line 1277 of file tcp.c.

1279  {
1280  int err;
1281  SOCKET socket;
1282 
1283  assert(xfer_type == UV__IPC_SOCKET_XFER_TCP_SERVER ||
1284  xfer_type == UV__IPC_SOCKET_XFER_TCP_CONNECTION);
1285 
1286  socket = WSASocketW(FROM_PROTOCOL_INFO,
1287  FROM_PROTOCOL_INFO,
1288  FROM_PROTOCOL_INFO,
1289  &xfer_info->socket_info,
1290  0,
1291  WSA_FLAG_OVERLAPPED);
1292 
1293  if (socket == INVALID_SOCKET) {
1294  return WSAGetLastError();
1295  }
1296 
1298  tcp->loop, tcp, socket, xfer_info->socket_info.iAddressFamily, 1);
1299  if (err) {
1300  closesocket(socket);
1301  return err;
1302  }
1303 
1304  tcp->delayed_error = xfer_info->delayed_error;
1306 
1307  if (xfer_type == UV__IPC_SOCKET_XFER_TCP_CONNECTION) {
1309  tcp->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
1310  }
1311 
1312  tcp->loop->active_tcp_streams++;
1313  return 0;
1314 }
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
static INLINE void uv_connection_init(uv_stream_t *handle)
Definition: stream-inl.h:49
@ UV_HANDLE_WRITABLE
Definition: uv-common.h:93
@ UV_HANDLE_READABLE
Definition: uv-common.h:92
static int uv_tcp_set_socket(uv_loop_t *loop, uv_tcp_t *handle, SOCKET socket, int family, int imported)
Definition: tcp.c:81

References assert(), uv__ipc_socket_xfer_info_t::delayed_error, err, socket, uv__ipc_socket_xfer_info_t::socket_info, UV__IPC_SOCKET_XFER_TCP_CONNECTION, UV__IPC_SOCKET_XFER_TCP_SERVER, uv_connection_init(), UV_HANDLE_BOUND, UV_HANDLE_READABLE, UV_HANDLE_SHARED_TCP_SOCKET, UV_HANDLE_WRITABLE, and uv_tcp_set_socket().

Referenced by uv_pipe_accept().

◆ uv__tty_try_write()

int uv__tty_try_write ( uv_tty_t handle,
const uv_buf_t  bufs[],
unsigned int  nbufs 
)

Definition at line 2212 of file tty.c.

2214  {
2215  DWORD error;
2216 
2217  if (handle->stream.conn.write_reqs_pending > 0)
2218  return UV_EAGAIN;
2219 
2220  if (uv_tty_write_bufs(handle, bufs, nbufs, &error))
2221  return uv_translate_sys_error(error);
2222 
2223  return uv__count_bufs(bufs, nbufs);
2224 }
size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs)
Definition: uv-common.c:573
static int uv_tty_write_bufs(uv_tty_t *handle, const uv_buf_t bufs[], unsigned int nbufs, DWORD *error)
Definition: tty.c:1673

References bufs, DWORD, error(), handle, uv__count_bufs(), uv_translate_sys_error(), and uv_tty_write_bufs().

Referenced by uv_try_write().

◆ uv__util_init()

void uv__util_init ( void  )

Definition at line 79 of file util.c.

79  {
80  LARGE_INTEGER perf_frequency;
81 
82  /* Initialize process title access mutex. */
83  InitializeCriticalSection(&process_title_lock);
84 
85  /* Retrieve high-resolution timer frequency
86  * and precompute its reciprocal.
87  */
88  if (QueryPerformanceFrequency(&perf_frequency)) {
89  hrtime_frequency_ = perf_frequency.QuadPart;
90  } else {
91  uv_fatal_error(GetLastError(), "QueryPerformanceFrequency");
92  }
93 }
static CRITICAL_SECTION process_title_lock
Definition: util.c:70

References hrtime_frequency_, process_title_lock, and uv_fatal_error().

Referenced by uv_init().

◆ uv__wake_all_loops()

void uv__wake_all_loops ( void  )

Definition at line 162 of file core.c.

162  {
163  int i;
164  uv_loop_t* loop;
165 
167  for (i = 0; i < uv__loops_size; ++i) {
168  loop = uv__loops[i];
169  assert(loop);
170  if (loop->iocp != INVALID_HANDLE_VALUE)
171  PostQueuedCompletionStatus(loop->iocp, 0, 0, NULL);
172  }
174 }
Definition: uv.h:1780
static int uv__loops_size
Definition: core.c:82
static uv_mutex_t uv__loops_lock
Definition: core.c:85
static uv_loop_t ** uv__loops
Definition: core.c:81
UV_EXTERN void uv_mutex_lock(uv_mutex_t *handle)
Definition: thread.c:330
UV_EXTERN void uv_mutex_unlock(uv_mutex_t *handle)
Definition: thread.c:350

References assert(), i, INVALID_HANDLE_VALUE, loop, NULL, uv__loops, uv__loops_lock, uv__loops_size, uv_mutex_lock(), and uv_mutex_unlock().

Referenced by uv__system_resume_callback().

◆ uv_async_close()

void uv_async_close ( uv_loop_t loop,
uv_async_t handle 
)

Definition at line 57 of file async.c.

57  {
58  if (!((uv_async_t*)handle)->async_sent) {
60  }
61 
63 }
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
Definition: handle-inl.h:88
#define uv__handle_closing(handle)
Definition: handle-inl.h:63
Definition: uv.h:844

References handle, loop, uv__handle_closing, and uv_want_endgame().

Referenced by uv_close().

◆ uv_async_endgame()

void uv_async_endgame ( uv_loop_t loop,
uv_async_t handle 
)

Definition at line 31 of file async.c.

31  {
32  if (handle->flags & UV_HANDLE_CLOSING &&
33  !handle->async_sent) {
34  assert(!(handle->flags & UV_HANDLE_CLOSED));
36  }
37 }
#define uv__handle_close(handle)
Definition: handle-inl.h:76
@ UV_HANDLE_CLOSING
Definition: uv-common.h:74
@ UV_HANDLE_CLOSED
Definition: uv-common.h:75

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

Referenced by uv_process_endgames().

◆ uv_check_invoke()

void uv_check_invoke ( uv_loop_t loop)

Referenced by uv_run().

◆ uv_console_init()

void uv_console_init ( void  )

Definition at line 166 of file tty.c.

166  {
168  abort();
169  uv__tty_console_handle = CreateFileW(L"CONOUT$",
170  GENERIC_READ | GENERIC_WRITE,
171  FILE_SHARE_WRITE,
172  0,
173  OPEN_EXISTING,
174  0,
175  0);
177  CONSOLE_SCREEN_BUFFER_INFO sb_info;
179  NULL,
180  WT_EXECUTELONGFUNCTION);
182  if (GetConsoleScreenBufferInfo(uv__tty_console_handle, &sb_info)) {
183  uv__tty_console_width = sb_info.dwSize.X;
184  uv__tty_console_height = sb_info.srWindow.Bottom - sb_info.srWindow.Top + 1;
185  }
186  }
187 }
UV_EXTERN int uv_sem_init(uv_sem_t *sem, unsigned int value)
Definition: thread.c:650
UV_EXTERN int uv_mutex_init(uv_mutex_t *handle)
Definition: thread.c:282
static uv_sem_t uv_tty_output_lock
Definition: tty.c:148
static int uv__tty_console_height
Definition: tty.c:128
static int uv__tty_console_width
Definition: tty.c:129
static uv_mutex_t uv__tty_console_resize_mutex
Definition: tty.c:131
static DWORD WINAPI uv__tty_console_resize_message_loop_thread(void *param)
Definition: tty.c:2349
static HANDLE uv__tty_console_handle
Definition: tty.c:127

References INVALID_HANDLE_VALUE, L, NULL, uv__tty_console_handle, uv__tty_console_height, uv__tty_console_resize_message_loop_thread(), uv__tty_console_resize_mutex, uv__tty_console_width, uv_mutex_init(), uv_sem_init(), and uv_tty_output_lock.

Referenced by uv_init().

◆ uv_fs_event_close()

void uv_fs_event_close ( uv_loop_t loop,
uv_fs_event_t handle 
)

Definition at line 585 of file fs-event.c.

585  {
587 
589 
590  if (!handle->req_pending) {
592  }
593 
594 }
int uv_fs_event_stop(uv_fs_event_t *handle)
Definition: fs-event.c:372

References handle, loop, uv__handle_closing, uv_fs_event_stop(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_fs_event_endgame()

void uv_fs_event_endgame ( uv_loop_t loop,
uv_fs_event_t handle 
)

Definition at line 597 of file fs-event.c.

597  {
598  if ((handle->flags & UV_HANDLE_CLOSING) && !handle->req_pending) {
599  assert(!(handle->flags & UV_HANDLE_CLOSED));
600 
601  if (handle->buffer) {
602  uv__free(handle->buffer);
603  handle->buffer = NULL;
604  }
605 
607  }
608 }

References assert(), handle, NULL, uv__free(), uv__handle_close, UV_HANDLE_CLOSED, and UV_HANDLE_CLOSING.

Referenced by uv_process_endgames().

◆ uv_fs_init()

void uv_fs_init ( void  )

Definition at line 141 of file fs.c.

141  {
142  SYSTEM_INFO system_info;
143 
144  GetSystemInfo(&system_info);
145  uv__allocation_granularity = system_info.dwAllocationGranularity;
146 
148 }
static INLINE void uv__fd_hash_init(void)
static DWORD uv__allocation_granularity
Definition: fs.c:138

References uv__allocation_granularity, and uv__fd_hash_init().

Referenced by uv_init().

◆ uv_get_acceptex_function()

BOOL uv_get_acceptex_function ( SOCKET  socket,
LPFN_ACCEPTEX target 
)

Definition at line 65 of file winsock.c.

65  {
66  const GUID wsaid_acceptex = WSAID_ACCEPTEX;
67  return uv_get_extension_function(socket, wsaid_acceptex, (void**)target);
68 }
#define WSAID_ACCEPTEX
Definition: win.h:109
static BOOL uv_get_extension_function(SOCKET socket, GUID guid, void **target)
Definition: winsock.c:41

References socket, uv_get_extension_function(), and WSAID_ACCEPTEX.

Referenced by uv_tcp_listen().

◆ uv_get_connectex_function()

BOOL uv_get_connectex_function ( SOCKET  socket,
LPFN_CONNECTEX target 
)

Definition at line 71 of file winsock.c.

71  {
72  const GUID wsaid_connectex = WSAID_CONNECTEX;
73  return uv_get_extension_function(socket, wsaid_connectex, (void**)target);
74 }
#define WSAID_CONNECTEX
Definition: win.h:113

References socket, uv_get_extension_function(), and WSAID_CONNECTEX.

Referenced by uv_tcp_try_connect().

◆ uv_idle_invoke()

void uv_idle_invoke ( uv_loop_t loop)

Referenced by uv_run().

◆ uv_loop_watcher_endgame()

void uv_loop_watcher_endgame ( uv_loop_t loop,
uv_handle_t handle 
)

Definition at line 29 of file loop-watcher.c.

29  {
30  if (handle->flags & UV_HANDLE_CLOSING) {
31  assert(!(handle->flags & UV_HANDLE_CLOSED));
32  handle->flags |= UV_HANDLE_CLOSED;
34  }
35 }

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

Referenced by uv_process_endgames().

◆ uv_msafd_poll()

int WSAAPI uv_msafd_poll ( SOCKET  socket,
AFD_POLL_INFO info_in,
AFD_POLL_INFO info_out,
OVERLAPPED *  overlapped 
)

Definition at line 461 of file winsock.c.

462  {
463  IO_STATUS_BLOCK iosb;
464  IO_STATUS_BLOCK* iosb_ptr;
465  HANDLE event = NULL;
466  void* apc_context;
468  DWORD error;
469 
470  if (overlapped != NULL) {
471  /* Overlapped operation. */
472  iosb_ptr = (IO_STATUS_BLOCK*) &overlapped->Internal;
473  event = overlapped->hEvent;
474 
475  /* Do not report iocp completion if hEvent is tagged. */
476  if ((uintptr_t) event & 1) {
477  event = (HANDLE)((uintptr_t) event & ~(uintptr_t) 1);
478  apc_context = NULL;
479  } else {
480  apc_context = overlapped;
481  }
482 
483  } else {
484  /* Blocking operation. */
485  iosb_ptr = &iosb;
486  event = CreateEvent(NULL, FALSE, FALSE, NULL);
487  if (event == NULL) {
488  return SOCKET_ERROR;
489  }
490  apc_context = NULL;
491  }
492 
493  iosb_ptr->Status = STATUS_PENDING;
495  event,
496  NULL,
497  apc_context,
498  iosb_ptr,
500  info_in,
501  sizeof *info_in,
502  info_out,
503  sizeof *info_out);
504 
505  if (overlapped == NULL) {
506  /* If this is a blocking operation, wait for the event to become signaled,
507  * and then grab the real status from the io status block. */
508  if (status == STATUS_PENDING) {
509  DWORD r = WaitForSingleObject(event, INFINITE);
510 
511  if (r == WAIT_FAILED) {
512  DWORD saved_error = GetLastError();
513  CloseHandle(event);
514  WSASetLastError(saved_error);
515  return SOCKET_ERROR;
516  }
517 
518  status = iosb.Status;
519  }
520 
521  CloseHandle(event);
522  }
523 
524  switch (status) {
525  case STATUS_SUCCESS:
526  error = ERROR_SUCCESS;
527  break;
528 
529  case STATUS_PENDING:
530  error = WSA_IO_PENDING;
531  break;
532 
533  default:
535  break;
536  }
537 
538  WSASetLastError(error);
539 
540  if (error == ERROR_SUCCESS) {
541  return 0;
542  } else {
543  return SOCKET_ERROR;
544  }
545 }
static const char struct stat static buf struct stat static buf static vhangup int status
Definition: sflib.h:145
_W64 unsigned int uintptr_t
NTSTATUS Status
Definition: winapi.h:4165
LONG NTSTATUS
Definition: win.h:198
sNtDeviceIoControlFile pNtDeviceIoControlFile
Definition: winapi.c:31
#define STATUS_PENDING
Definition: winapi.h:120
#define STATUS_SUCCESS
Definition: winapi.h:68
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4
int uv_ntstatus_to_winsock_error(NTSTATUS status)
Definition: winsock.c:137
#define IOCTL_AFD_POLL
Definition: winsock.h:154

References DWORD, error(), FALSE, HANDLE, if(), IOCTL_AFD_POLL, NULL, pNtDeviceIoControlFile, r, socket, status, _IO_STATUS_BLOCK::Status, STATUS_PENDING, STATUS_SUCCESS, and uv_ntstatus_to_winsock_error().

Referenced by uv__fast_poll_submit_poll_req(), and uv_poll_close().

◆ uv_ntstatus_to_winsock_error()

int uv_ntstatus_to_winsock_error ( NTSTATUS  status)

Definition at line 137 of file winsock.c.

137  {
138  switch (status) {
139  case STATUS_SUCCESS:
140  return ERROR_SUCCESS;
141 
142  case STATUS_PENDING:
143  return ERROR_IO_PENDING;
144 
147  return WSAENOTSOCK;
148 
153  case STATUS_NO_MEMORY:
157  return WSAENOBUFS;
158 
162  return WSAEADDRINUSE;
163 
164  case STATUS_LINK_TIMEOUT:
165  case STATUS_IO_TIMEOUT:
166  case STATUS_TIMEOUT:
167  return WSAETIMEDOUT;
168 
170  return WSAEDISCON;
171 
174  case STATUS_LINK_FAILED:
178  return WSAECONNRESET;
179 
183  return WSAECONNABORTED;
184 
188  return WSAENETUNREACH;
189 
191  return WSAEHOSTUNREACH;
192 
193  case STATUS_CANCELLED:
195  return WSAEINTR;
196 
199  return WSAEMSGSIZE;
200 
203  return WSAEFAULT;
204 
207  return WSAEWOULDBLOCK;
208 
210  case STATUS_NETWORK_BUSY:
212  case STATUS_NO_SUCH_FILE:
216  return WSAENETDOWN;
217 
219  return WSAENOTCONN;
220 
223  return WSAECONNREFUSED;
224 
226  return WSAESHUTDOWN;
227 
231  return WSAEADDRNOTAVAIL;
232 
235  return WSAEOPNOTSUPP;
236 
238  return WSAEACCES;
239 
240  default:
241  if ((status & (FACILITY_NTWIN32 << 16)) == (FACILITY_NTWIN32 << 16) &&
242  (status & (ERROR_SEVERITY_ERROR | ERROR_SEVERITY_WARNING))) {
243  /* It's a windows error that has been previously mapped to an ntstatus
244  * code. */
245  return (DWORD) (status & 0xffff);
246  } else {
247  /* The default fallback for unmappable ntstatus codes. */
248  return WSAEINVAL;
249  }
250  }
251 }
#define STATUS_TIMEOUT
Definition: winapi.h:116
#define STATUS_PIPE_DISCONNECTED
Definition: winapi.h:1376
#define STATUS_INVALID_ADDRESS
Definition: winapi.h:1956
#define STATUS_INVALID_HANDLE
Definition: winapi.h:708
#define STATUS_QUOTA_EXCEEDED
Definition: winapi.h:944
#define STATUS_NETWORK_UNREACHABLE
Definition: winapi.h:2576
#define STATUS_DEVICE_NOT_READY
Definition: winapi.h:1324
#define STATUS_PROTOCOL_UNREACHABLE
Definition: winapi.h:2584
#define STATUS_ADDRESS_ALREADY_EXISTS
Definition: winapi.h:2376
#define STATUS_GRACEFUL_DISCONNECT
Definition: winapi.h:2556
#define STATUS_INVALID_BUFFER_SIZE
Definition: winapi.h:2360
#define STATUS_TRANSACTION_ABORTED
Definition: winapi.h:2396
#define STATUS_ACCESS_DENIED
Definition: winapi.h:812
#define STATUS_OBJECT_PATH_NOT_FOUND
Definition: winapi.h:904
#define STATUS_HOST_UNREACHABLE
Definition: winapi.h:2580
#define STATUS_WORKING_SET_QUOTA
Definition: winapi.h:1316
#define STATUS_REMOTE_DISCONNECT
Definition: winapi.h:1936
#define STATUS_INVALID_CONNECTION
Definition: winapi.h:1952
#define STATUS_PORT_UNREACHABLE
Definition: winapi.h:2588
#define STATUS_NETWORK_BUSY
Definition: winapi.h:1436
#define STATUS_IO_TIMEOUT
Definition: winapi.h:1396
#define STATUS_INVALID_NETWORK_RESPONSE
Definition: winapi.h:1452
#define STATUS_CONNECTION_RESET
Definition: winapi.h:2388
#define STATUS_NO_SUCH_DEVICE
Definition: winapi.h:732
#define STATUS_REQUEST_ABORTED
Definition: winapi.h:2592
#define STATUS_NO_MEMORY
Definition: winapi.h:768
#define STATUS_CONNECTION_ABORTED
Definition: winapi.h:2596
#define STATUS_NOT_SUPPORTED
Definition: winapi.h:1420
#define STATUS_BAD_NETWORK_PATH
Definition: winapi.h:1432
#define STATUS_CONNECTION_REFUSED
Definition: winapi.h:2552
#define STATUS_INVALID_ADDRESS_COMPONENT
Definition: winapi.h:2364
#define STATUS_ACCESS_VIOLATION
Definition: winapi.h:696
#define STATUS_NOT_IMPLEMENTED
Definition: winapi.h:684
#define STATUS_CONNECTION_DISCONNECTED
Definition: winapi.h:2384
#define FACILITY_NTWIN32
Definition: winapi.h:48
#define STATUS_NO_SUCH_FILE
Definition: winapi.h:736
#define STATUS_LINK_TIMEOUT
Definition: winapi.h:1948
#define STATUS_CONFLICTING_ADDRESSES
Definition: winapi.h:772
#define STATUS_REMOTE_NOT_LISTENING
Definition: winapi.h:1424
#define STATUS_REMOTE_RESOURCES
Definition: winapi.h:1940
#define STATUS_LINK_FAILED
Definition: winapi.h:1944
#define STATUS_BUFFER_TOO_SMALL
Definition: winapi.h:816
#define STATUS_BUFFER_OVERFLOW
Definition: winapi.h:520
#define STATUS_UNEXPECTED_NETWORK_ERROR
Definition: winapi.h:1456
#define STATUS_HOPLIMIT_EXCEEDED
Definition: winapi.h:4024
#define STATUS_LOCAL_DISCONNECT
Definition: winapi.h:1932
#define STATUS_SHARING_VIOLATION
Definition: winapi.h:940
#define STATUS_INSUFFICIENT_RESOURCES
Definition: winapi.h:1288
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: winapi.h:884
#define STATUS_CANCELLED
Definition: winapi.h:1824
#define STATUS_REQUEST_NOT_ACCEPTED
Definition: winapi.h:1504
#define STATUS_PAGEFILE_QUOTA
Definition: winapi.h:704
#define STATUS_TOO_MANY_ADDRESSES
Definition: winapi.h:2372
#define STATUS_TOO_MANY_PAGING_FILES
Definition: winapi.h:1276
#define STATUS_COMMITMENT_LIMIT
Definition: winapi.h:1876
#define STATUS_OBJECT_TYPE_MISMATCH
Definition: winapi.h:820

References DWORD, FACILITY_NTWIN32, status, STATUS_ACCESS_DENIED, STATUS_ACCESS_VIOLATION, STATUS_ADDRESS_ALREADY_EXISTS, STATUS_BAD_NETWORK_PATH, STATUS_BUFFER_OVERFLOW, STATUS_BUFFER_TOO_SMALL, STATUS_CANCELLED, STATUS_COMMITMENT_LIMIT, STATUS_CONFLICTING_ADDRESSES, STATUS_CONNECTION_ABORTED, STATUS_CONNECTION_DISCONNECTED, STATUS_CONNECTION_REFUSED, STATUS_CONNECTION_RESET, STATUS_DEVICE_NOT_READY, STATUS_GRACEFUL_DISCONNECT, STATUS_HOPLIMIT_EXCEEDED, STATUS_HOST_UNREACHABLE, STATUS_INSUFFICIENT_RESOURCES, STATUS_INVALID_ADDRESS, STATUS_INVALID_ADDRESS_COMPONENT, STATUS_INVALID_BUFFER_SIZE, STATUS_INVALID_CONNECTION, STATUS_INVALID_HANDLE, STATUS_INVALID_NETWORK_RESPONSE, STATUS_IO_TIMEOUT, STATUS_LINK_FAILED, STATUS_LINK_TIMEOUT, STATUS_LOCAL_DISCONNECT, STATUS_NETWORK_BUSY, STATUS_NETWORK_UNREACHABLE, STATUS_NO_MEMORY, STATUS_NO_SUCH_DEVICE, STATUS_NO_SUCH_FILE, STATUS_NOT_IMPLEMENTED, STATUS_NOT_SUPPORTED, STATUS_OBJECT_NAME_NOT_FOUND, STATUS_OBJECT_PATH_NOT_FOUND, STATUS_OBJECT_TYPE_MISMATCH, STATUS_PAGEFILE_QUOTA, STATUS_PENDING, STATUS_PIPE_DISCONNECTED, STATUS_PORT_UNREACHABLE, STATUS_PROTOCOL_UNREACHABLE, STATUS_QUOTA_EXCEEDED, STATUS_REMOTE_DISCONNECT, STATUS_REMOTE_NOT_LISTENING, STATUS_REMOTE_RESOURCES, STATUS_REQUEST_ABORTED, STATUS_REQUEST_NOT_ACCEPTED, STATUS_SHARING_VIOLATION, STATUS_SUCCESS, STATUS_TIMEOUT, STATUS_TOO_MANY_ADDRESSES, STATUS_TOO_MANY_PAGING_FILES, STATUS_TRANSACTION_ABORTED, STATUS_UNEXPECTED_NETWORK_ERROR, and STATUS_WORKING_SET_QUOTA.

Referenced by uv_msafd_poll(), uv_wsarecv_workaround(), and uv_wsarecvfrom_workaround().

◆ uv_pipe_accept()

int uv_pipe_accept ( uv_pipe_t server,
uv_stream_t client 
)

Definition at line 876 of file pipe.c.

876  {
877  uv_loop_t* loop = server->loop;
878  uv_pipe_t* pipe_client;
879  uv_pipe_accept_t* req;
880  QUEUE* q;
882  int err;
883 
884  if (server->ipc) {
885  if (QUEUE_EMPTY(&server->pipe.conn.ipc_xfer_queue)) {
886  /* No valid pending sockets. */
887  return WSAEWOULDBLOCK;
888  }
889 
890  q = QUEUE_HEAD(&server->pipe.conn.ipc_xfer_queue);
891  QUEUE_REMOVE(q);
892  server->pipe.conn.ipc_xfer_queue_length--;
893  item = QUEUE_DATA(q, uv__ipc_xfer_queue_item_t, member);
894 
896  (uv_tcp_t*) client, item->xfer_type, &item->xfer_info);
897  if (err != 0)
898  return err;
899 
900  uv__free(item);
901 
902  } else {
903  pipe_client = (uv_pipe_t*) client;
904 
905  /* Find a connection instance that has been connected, but not yet
906  * accepted. */
907  req = server->pipe.serv.pending_accepts;
908 
909  if (!req) {
910  /* No valid connections found, so we error out. */
911  return WSAEWOULDBLOCK;
912  }
913 
914  /* Initialize the client handle and copy the pipeHandle to the client */
915  uv_pipe_connection_init(pipe_client);
916  pipe_client->handle = req->pipeHandle;
917  pipe_client->flags |= UV_HANDLE_READABLE | UV_HANDLE_WRITABLE;
918 
919  /* Prepare the req to pick up a new connection */
920  server->pipe.serv.pending_accepts = req->next_pending;
921  req->next_pending = NULL;
922  req->pipeHandle = INVALID_HANDLE_VALUE;
923 
924  server->handle = INVALID_HANDLE_VALUE;
925  if (!(server->flags & UV_HANDLE_CLOSING)) {
926  uv_pipe_queue_accept(loop, server, req, FALSE);
927  }
928  }
929 
930  return 0;
931 }
#define QUEUE_DATA(ptr, type, field)
Definition: queue.h:30
#define QUEUE_EMPTY(q)
Definition: queue.h:39
#define QUEUE_HEAD(q)
Definition: queue.h:42
void * QUEUE[2]
Definition: queue.h:21
#define QUEUE_REMOVE(q)
Definition: queue.h:101
uv__ipc_socket_xfer_info_t xfer_info
Definition: pipe.c:57
uv__ipc_socket_xfer_type_t xfer_type
Definition: pipe.c:56
UV_HANDLE_FIELDS UV_STREAM_FIELDS int ipc
Definition: uv.h:770
Definition: uv.h:547
int uv__tcp_xfer_import(uv_tcp_t *tcp, uv__ipc_socket_xfer_type_t xfer_type, uv__ipc_socket_xfer_info_t *xfer_info)
Definition: tcp.c:1277
static void uv_pipe_queue_accept(uv_loop_t *loop, uv_pipe_t *handle, uv_pipe_accept_t *req, BOOL firstInstance)
Definition: pipe.c:840
static void uv_pipe_connection_init(uv_pipe_t *handle)
Definition: pipe.c:123

References err, FALSE, INVALID_HANDLE_VALUE, uv_pipe_s::ipc, loop, NULL, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_REMOVE, req, uv__free(), uv__tcp_xfer_import(), UV_HANDLE_CLOSING, UV_HANDLE_READABLE, UV_HANDLE_WRITABLE, uv_pipe_connection_init(), uv_pipe_queue_accept(), uv__ipc_xfer_queue_item_t::xfer_info, and uv__ipc_xfer_queue_item_t::xfer_type.

Referenced by uv_accept().

◆ uv_pipe_cleanup()

void uv_pipe_cleanup ( uv_loop_t loop,
uv_pipe_t handle 
)

Definition at line 785 of file pipe.c.

785  {
786  int i;
787  HANDLE pipeHandle;
788 
790 
791  if (handle->name) {
792  uv__free(handle->name);
793  handle->name = NULL;
794  }
795 
796  if (handle->flags & UV_HANDLE_PIPESERVER) {
797  for (i = 0; i < handle->pipe.serv.pending_instances; i++) {
798  pipeHandle = handle->pipe.serv.accept_reqs[i].pipeHandle;
799  if (pipeHandle != INVALID_HANDLE_VALUE) {
800  CloseHandle(pipeHandle);
801  handle->pipe.serv.accept_reqs[i].pipeHandle = INVALID_HANDLE_VALUE;
802  }
803  }
804  handle->handle = INVALID_HANDLE_VALUE;
805  }
806 
807  if (handle->flags & UV_HANDLE_CONNECTION) {
808  handle->flags &= ~UV_HANDLE_WRITABLE;
810  }
811 
812  if ((handle->flags & UV_HANDLE_CONNECTION)
813  && handle->handle != INVALID_HANDLE_VALUE)
815 }
static void eof_timer_destroy(uv_pipe_t *pipe)
Definition: pipe.c:2065
static void close_pipe(uv_pipe_t *pipe)
Definition: pipe.c:193

References close_pipe(), eof_timer_destroy(), handle, HANDLE, i, INVALID_HANDLE_VALUE, NULL, uv__free(), uv__pipe_interrupt_read(), UV_HANDLE_CONNECTION, UV_HANDLE_PIPESERVER, and UV_HANDLE_WRITABLE.

Referenced by uv__create_stdio_pipe_pair(), and uv_pipe_close().

◆ uv_pipe_close()

void uv_pipe_close ( uv_loop_t loop,
uv_pipe_t handle 
)

Definition at line 818 of file pipe.c.

818  {
819  if (handle->flags & UV_HANDLE_READING) {
820  handle->flags &= ~UV_HANDLE_READING;
822  }
823 
824  if (handle->flags & UV_HANDLE_LISTENING) {
825  handle->flags &= ~UV_HANDLE_LISTENING;
827  }
828 
830 
831  if (handle->reqs_pending == 0) {
833  }
834 
837 }
void uv_pipe_cleanup(uv_loop_t *loop, uv_pipe_t *handle)
Definition: pipe.c:785

References DECREASE_ACTIVE_COUNT, handle, loop, uv__handle_closing, UV_HANDLE_LISTENING, UV_HANDLE_READABLE, UV_HANDLE_READING, UV_HANDLE_WRITABLE, uv_pipe_cleanup(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_pipe_endgame()

void uv_pipe_endgame ( uv_loop_t loop,
uv_pipe_t handle 
)

Definition at line 382 of file pipe.c.

382  {
383  int err;
384  DWORD result;
386  NTSTATUS nt_status;
387  IO_STATUS_BLOCK io_status;
388  FILE_PIPE_LOCAL_INFORMATION pipe_info;
389  uv__ipc_xfer_queue_item_t* xfer_queue_item;
390 
391  if ((handle->flags & UV_HANDLE_CONNECTION) &&
392  handle->stream.conn.shutdown_req != NULL &&
393  handle->stream.conn.write_reqs_pending == 0) {
394  req = handle->stream.conn.shutdown_req;
395 
396  /* Clear the shutdown_req field so we don't go here again. */
397  handle->stream.conn.shutdown_req = NULL;
398 
399  if (handle->flags & UV_HANDLE_CLOSING) {
401 
402  /* Already closing. Cancel the shutdown. */
403  if (req->cb) {
404  req->cb(req, UV_ECANCELED);
405  }
406 
408  return;
409  }
410 
411  /* Try to avoid flushing the pipe buffer in the thread pool. */
412  nt_status = pNtQueryInformationFile(handle->handle,
413  &io_status,
414  &pipe_info,
415  sizeof pipe_info,
417 
418  if (nt_status != STATUS_SUCCESS) {
419  /* Failure */
421 
422  handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */
423  if (req->cb) {
424  err = pRtlNtStatusToDosError(nt_status);
426  }
427 
429  return;
430  }
431 
432  if (pipe_info.OutboundQuota == pipe_info.WriteQuotaAvailable) {
433  /* Short-circuit, no need to call FlushFileBuffers. */
435  return;
436  }
437 
438  /* Run FlushFileBuffers in the thread pool. */
439  result = QueueUserWorkItem(pipe_shutdown_thread_proc,
440  req,
441  WT_EXECUTELONGFUNCTION);
442  if (result) {
443  return;
444 
445  } else {
446  /* Failure. */
448 
449  handle->flags |= UV_HANDLE_WRITABLE; /* Questionable */
450  if (req->cb) {
451  err = GetLastError();
453  }
454 
456  return;
457  }
458  }
459 
460  if (handle->flags & UV_HANDLE_CLOSING &&
461  handle->reqs_pending == 0) {
462  assert(!(handle->flags & UV_HANDLE_CLOSED));
463 
464  if (handle->flags & UV_HANDLE_CONNECTION) {
465  /* Free pending sockets */
466  while (!QUEUE_EMPTY(&handle->pipe.conn.ipc_xfer_queue)) {
467  QUEUE* q;
468  SOCKET socket;
469 
470  q = QUEUE_HEAD(&handle->pipe.conn.ipc_xfer_queue);
471  QUEUE_REMOVE(q);
472  xfer_queue_item = QUEUE_DATA(q, uv__ipc_xfer_queue_item_t, member);
473 
474  /* Materialize socket and close it */
475  socket = WSASocketW(FROM_PROTOCOL_INFO,
476  FROM_PROTOCOL_INFO,
477  FROM_PROTOCOL_INFO,
478  &xfer_queue_item->xfer_info.socket_info,
479  0,
480  WSA_FLAG_OVERLAPPED);
481  uv__free(xfer_queue_item);
482 
483  if (socket != INVALID_SOCKET)
484  closesocket(socket);
485  }
486  handle->pipe.conn.ipc_xfer_queue_length = 0;
487 
488  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
489  if (handle->read_req.wait_handle != INVALID_HANDLE_VALUE) {
490  UnregisterWait(handle->read_req.wait_handle);
491  handle->read_req.wait_handle = INVALID_HANDLE_VALUE;
492  }
493  if (handle->read_req.event_handle != NULL) {
494  CloseHandle(handle->read_req.event_handle);
495  handle->read_req.event_handle = NULL;
496  }
497  }
498 
500  DeleteCriticalSection(&handle->pipe.conn.readfile_thread_lock);
501  }
502 
503  if (handle->flags & UV_HANDLE_PIPESERVER) {
504  assert(handle->pipe.serv.accept_reqs);
505  uv__free(handle->pipe.serv.accept_reqs);
506  handle->pipe.serv.accept_reqs = NULL;
507  }
508 
510  }
511 }
#define DECREASE_PENDING_REQ_COUNT(handle)
Definition: handle-inl.h:51
static INLINE void uv_insert_pending_req(uv_loop_t *loop, uv_req_t *req)
Definition: req-inl.h:90
#define UNREGISTER_HANDLE_REQ(loop, handle, req)
Definition: req-inl.h:62
Definition: uv.h:407
static DWORD WINAPI pipe_shutdown_thread_proc(void *parameter)
Definition: pipe.c:361
@ UV_HANDLE_EMULATE_IOCP
Definition: uv-common.h:97
@ UV_HANDLE_NON_OVERLAPPED_PIPE
Definition: uv-common.h:118
sNtQueryInformationFile pNtQueryInformationFile
Definition: winapi.c:32
sRtlNtStatusToDosError pRtlNtStatusToDosError
Definition: winapi.c:30
@ FilePipeLocalInformation
Definition: winapi.h:4195

References assert(), DECREASE_PENDING_REQ_COUNT, DWORD, err, FilePipeLocalInformation, handle, INVALID_HANDLE_VALUE, loop, NULL, _FILE_PIPE_LOCAL_INFORMATION::OutboundQuota, pipe_shutdown_thread_proc(), pNtQueryInformationFile, pRtlNtStatusToDosError, QUEUE_DATA, QUEUE_EMPTY, QUEUE_HEAD, QUEUE_REMOVE, req, socket, uv__ipc_socket_xfer_info_t::socket_info, STATUS_SUCCESS, UNREGISTER_HANDLE_REQ, uv__free(), uv__handle_close, UV_HANDLE_CLOSED, UV_HANDLE_CLOSING, UV_HANDLE_CONNECTION, UV_HANDLE_EMULATE_IOCP, UV_HANDLE_NON_OVERLAPPED_PIPE, UV_HANDLE_PIPESERVER, UV_HANDLE_WRITABLE, uv_insert_pending_req(), uv_translate_sys_error(), _FILE_PIPE_LOCAL_INFORMATION::WriteQuotaAvailable, and uv__ipc_xfer_queue_item_t::xfer_info.

Referenced by uv_process_endgames().

◆ 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 }
#define UV__ERR(x)
Definition: errno.h:29
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: core.c:882
void uv__server_io(uv_loop_t *loop, uv__io_t *w, unsigned int events)
Definition: stream.c:528
#define uv__stream_fd(handle)
Definition: internal.h:282

References assert(), cb, handle, i, INCREASE_ACTIVE_COUNT, INVALID_HANDLE_VALUE, loop, UV_HANDLE_BOUND, UV_HANDLE_LISTENING, UV_HANDLE_PIPESERVER, UV_HANDLE_READING, and uv_pipe_queue_accept().

◆ uv_pipe_read_start()

int uv_pipe_read_start ( uv_pipe_t handle,
uv_alloc_cb  alloc_cb,
uv_read_cb  read_cb 
)

Definition at line 1177 of file pipe.c.

1179  {
1180  uv_loop_t* loop = handle->loop;
1181 
1182  handle->flags |= UV_HANDLE_READING;
1184  handle->read_cb = read_cb;
1185  handle->alloc_cb = alloc_cb;
1186 
1187  /* If reading was stopped and then started again, there could still be a read
1188  * request pending. */
1189  if (!(handle->flags & UV_HANDLE_READ_PENDING)) {
1190  if (handle->flags & UV_HANDLE_EMULATE_IOCP &&
1191  handle->read_req.event_handle == NULL) {
1192  handle->read_req.event_handle = CreateEvent(NULL, 0, 0, NULL);
1193  if (handle->read_req.event_handle == NULL) {
1194  uv_fatal_error(GetLastError(), "CreateEvent");
1195  }
1196  }
1198  }
1199 
1200  return 0;
1201 }
#define INCREASE_ACTIVE_COUNT(loop, handle)
Definition: handle-inl.h:42
static void uv_pipe_queue_read(uv_loop_t *loop, uv_pipe_t *handle)
Definition: pipe.c:1112
@ UV_HANDLE_READ_PENDING
Definition: uv-common.h:94

References handle, INCREASE_ACTIVE_COUNT, loop, NULL, uv_fatal_error(), UV_HANDLE_EMULATE_IOCP, UV_HANDLE_READ_PENDING, UV_HANDLE_READING, and uv_pipe_queue_read().

Referenced by uv_read_start().

◆ uv_poll_close()

int uv_poll_close ( uv_loop_t loop,
uv_poll_t handle 
)

Definition at line 535 of file poll.c.

535  {
536  AFD_POLL_INFO afd_poll_info;
537  DWORD error;
538  int result;
539 
540  handle->events = 0;
542 
543  if (handle->submitted_events_1 == 0 &&
544  handle->submitted_events_2 == 0) {
546  return 0;
547  }
548 
549  if (handle->flags & UV_HANDLE_POLL_SLOW)
550  return 0;
551 
552  /* Cancel outstanding poll requests by executing another, unique poll
553  * request that forces the outstanding ones to return. */
554  afd_poll_info.Exclusive = TRUE;
555  afd_poll_info.NumberOfHandles = 1;
556  afd_poll_info.Timeout.QuadPart = INT64_MAX;
557  afd_poll_info.Handles[0].Handle = (HANDLE) handle->socket;
558  afd_poll_info.Handles[0].Status = 0;
559  afd_poll_info.Handles[0].Events = AFD_POLL_ALL;
560 
561  result = uv_msafd_poll(handle->socket,
562  &afd_poll_info,
565 
566  if (result == SOCKET_ERROR) {
567  error = WSAGetLastError();
568  if (error != WSA_IO_PENDING)
570  }
571 
572  return 0;
573 }
#define TRUE
Definition: mybfd.h:103
#define INT64_MAX
NTSTATUS Status
Definition: win.h:209
LARGE_INTEGER Timeout
Definition: win.h:213
ULONG NumberOfHandles
Definition: win.h:214
ULONG Exclusive
Definition: win.h:215
AFD_POLL_HANDLE_INFO Handles[1]
Definition: win.h:216
int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO *info_in, AFD_POLL_INFO *info_out, OVERLAPPED *overlapped)
Definition: winsock.c:461
@ UV_HANDLE_POLL_SLOW
Definition: uv-common.h:132
static OVERLAPPED * uv__get_overlapped_dummy(void)
Definition: poll.c:64
static AFD_POLL_INFO * uv__get_afd_poll_info_dummy(void)
Definition: poll.c:70
#define AFD_POLL_ALL
Definition: winsock.h:120

References AFD_POLL_ALL, DWORD, error(), _AFD_POLL_HANDLE_INFO::Events, _AFD_POLL_INFO::Exclusive, handle, HANDLE, _AFD_POLL_HANDLE_INFO::Handle, _AFD_POLL_INFO::Handles, INT64_MAX, loop, _AFD_POLL_INFO::NumberOfHandles, _AFD_POLL_HANDLE_INFO::Status, _AFD_POLL_INFO::Timeout, TRUE, uv__get_afd_poll_info_dummy(), uv__get_overlapped_dummy(), uv__handle_closing, UV_HANDLE_POLL_SLOW, uv_msafd_poll(), uv_translate_sys_error(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_poll_endgame()

void uv_poll_endgame ( uv_loop_t loop,
uv_poll_t handle 
)

Definition at line 576 of file poll.c.

576  {
577  assert(handle->flags & UV_HANDLE_CLOSING);
578  assert(!(handle->flags & UV_HANDLE_CLOSED));
579 
580  assert(handle->submitted_events_1 == 0);
581  assert(handle->submitted_events_2 == 0);
582 
584 }

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

Referenced by uv_process_endgames().

◆ uv_prepare_invoke()

void uv_prepare_invoke ( uv_loop_t loop)

Referenced by uv_run().

◆ uv_process_async_wakeup_req()

void uv_process_async_wakeup_req ( uv_loop_t loop,
uv_async_t handle,
uv_req_t req 
)

Definition at line 86 of file async.c.

87  {
88  assert(handle->type == UV_ASYNC);
89  assert(req->type == UV_WAKEUP);
90 
91  handle->async_sent = 0;
92 
93  if (handle->flags & UV_HANDLE_CLOSING) {
95  } else if (handle->async_cb != NULL) {
96  handle->async_cb(handle);
97  }
98 }

References assert(), handle, loop, NULL, req, UV_HANDLE_CLOSING, and uv_want_endgame().

Referenced by uv_process_reqs().

◆ uv_process_close()

void uv_process_close ( uv_loop_t loop,
uv_process_t handle 
)

Definition at line 903 of file process.c.

903  {
905 
906  if (handle->wait_handle != INVALID_HANDLE_VALUE) {
907  /* This blocks until either the wait was cancelled, or the callback has
908  * completed. */
909  BOOL r = UnregisterWaitEx(handle->wait_handle, INVALID_HANDLE_VALUE);
910  if (!r) {
911  /* This should never happen, and if it happens, we can't recover... */
912  uv_fatal_error(GetLastError(), "UnregisterWaitEx");
913  }
914 
915  handle->wait_handle = INVALID_HANDLE_VALUE;
916  }
917 
918  if (!handle->exit_cb_pending) {
920  }
921 }

References handle, INVALID_HANDLE_VALUE, loop, r, uv__handle_closing, uv_fatal_error(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_process_endgame()

void uv_process_endgame ( uv_loop_t loop,
uv_process_t handle 
)

Definition at line 924 of file process.c.

924  {
925  assert(!handle->exit_cb_pending);
926  assert(handle->flags & UV_HANDLE_CLOSING);
927  assert(!(handle->flags & UV_HANDLE_CLOSED));
928 
929  /* Clean-up the process handle. */
930  CloseHandle(handle->process_handle);
931 
933 }

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

Referenced by uv_process_endgames().

◆ uv_process_fs_event_req()

void uv_process_fs_event_req ( uv_loop_t loop,
uv_req_t req,
uv_fs_event_t handle 
)

Definition at line 426 of file fs-event.c.

427  {
428  FILE_NOTIFY_INFORMATION* file_info;
429  int err, sizew, size;
430  char* filename = NULL;
431  WCHAR* filenamew = NULL;
432  WCHAR* long_filenamew = NULL;
433  DWORD offset = 0;
434 
435  assert(req->type == UV_FS_EVENT_REQ);
436  assert(handle->req_pending);
437  handle->req_pending = 0;
438 
439  /* Don't report any callbacks if:
440  * - We're closing, just push the handle onto the endgame queue
441  * - We are not active, just ignore the callback
442  */
443  if (!uv__is_active(handle)) {
444  if (handle->flags & UV_HANDLE_CLOSING) {
446  }
447  return;
448  }
449 
450  file_info = (FILE_NOTIFY_INFORMATION*)(handle->buffer + offset);
451 
452  if (REQ_SUCCESS(req)) {
453  if (req->u.io.overlapped.InternalHigh > 0) {
454  do {
455  file_info = (FILE_NOTIFY_INFORMATION*)((char*)file_info + offset);
456  assert(!filename);
457  assert(!filenamew);
458  assert(!long_filenamew);
459 
460  /*
461  * Fire the event only if we were asked to watch a directory,
462  * or if the filename filter matches.
463  */
464  if (handle->dirw ||
465  file_info_cmp(handle->filew,
466  file_info->FileName,
467  file_info->FileNameLength) == 0 ||
468  file_info_cmp(handle->short_filew,
469  file_info->FileName,
470  file_info->FileNameLength) == 0) {
471 
472  if (handle->dirw) {
473  /*
474  * We attempt to resolve the long form of the file name explicitly.
475  * We only do this for file names that might still exist on disk.
476  * If this fails, we use the name given by ReadDirectoryChangesW.
477  * This may be the long form or the 8.3 short name in some cases.
478  */
479  if (file_info->Action != FILE_ACTION_REMOVED &&
480  file_info->Action != FILE_ACTION_RENAMED_OLD_NAME) {
481  /* Construct a full path to the file. */
482  size = wcslen(handle->dirw) +
483  file_info->FileNameLength / sizeof(WCHAR) + 2;
484 
485  filenamew = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
486  if (!filenamew) {
487  uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
488  }
489 
490  _snwprintf(filenamew, size, L"%s\\%.*s", handle->dirw,
491  file_info->FileNameLength / (DWORD)sizeof(WCHAR),
492  file_info->FileName);
493 
494  filenamew[size - 1] = L'\0';
495 
496  /* Convert to long name. */
497  size = GetLongPathNameW(filenamew, NULL, 0);
498 
499  if (size) {
500  long_filenamew = (WCHAR*)uv__malloc(size * sizeof(WCHAR));
501  if (!long_filenamew) {
502  uv_fatal_error(ERROR_OUTOFMEMORY, "uv__malloc");
503  }
504 
505  size = GetLongPathNameW(filenamew, long_filenamew, size);
506  if (size) {
507  long_filenamew[size] = '\0';
508  } else {
509  uv__free(long_filenamew);
510  long_filenamew = NULL;
511  }
512  }
513 
514  uv__free(filenamew);
515 
516  if (long_filenamew) {
517  /* Get the file name out of the long path. */
518  uv_relative_path(long_filenamew,
519  handle->dirw,
520  &filenamew);
521  uv__free(long_filenamew);
522  long_filenamew = filenamew;
523  sizew = -1;
524  } else {
525  /* We couldn't get the long filename, use the one reported. */
526  filenamew = file_info->FileName;
527  sizew = file_info->FileNameLength / sizeof(WCHAR);
528  }
529  } else {
530  /*
531  * Removed or renamed events cannot be resolved to the long form.
532  * We therefore use the name given by ReadDirectoryChangesW.
533  * This may be the long form or the 8.3 short name in some cases.
534  */
535  filenamew = file_info->FileName;
536  sizew = file_info->FileNameLength / sizeof(WCHAR);
537  }
538  } else {
539  /* We already have the long name of the file, so just use it. */
540  filenamew = handle->filew;
541  sizew = -1;
542  }
543 
544  /* Convert the filename to utf8. */
545  uv__convert_utf16_to_utf8(filenamew, sizew, &filename);
546 
547  switch (file_info->Action) {
548  case FILE_ACTION_ADDED:
549  case FILE_ACTION_REMOVED:
550  case FILE_ACTION_RENAMED_OLD_NAME:
551  case FILE_ACTION_RENAMED_NEW_NAME:
552  handle->cb(handle, filename, UV_RENAME, 0);
553  break;
554 
555  case FILE_ACTION_MODIFIED:
556  handle->cb(handle, filename, UV_CHANGE, 0);
557  break;
558  }
559 
561  filename = NULL;
562  uv__free(long_filenamew);
563  long_filenamew = NULL;
564  filenamew = NULL;
565  }
566 
567  offset = file_info->NextEntryOffset;
568  } while (offset && !(handle->flags & UV_HANDLE_CLOSING));
569  } else {
570  handle->cb(handle, NULL, UV_CHANGE, 0);
571  }
572  } else {
573  err = GET_REQ_ERROR(req);
575  }
576 
577  if (!(handle->flags & UV_HANDLE_CLOSING)) {
579  } else {
581  }
582 }
static void uv_relative_path(const WCHAR *filename, const WCHAR *dir, WCHAR **relpath)
Definition: fs-event.c:66
static void uv_fs_event_queue_readdirchanges(uv_loop_t *loop, uv_fs_event_t *handle)
Definition: fs-event.c:36
static int file_info_cmp(WCHAR *str, WCHAR *file_name, size_t file_name_len)
Definition: fs-event.c:407
const char * filename
Definition: ioapi.h:137
voidpf uLong offset
Definition: ioapi.h:144
#define GET_REQ_ERROR(req)
Definition: req-inl.h:49
#define REQ_SUCCESS(req)
Definition: req-inl.h:46
int uv__convert_utf16_to_utf8(const WCHAR *utf16, int utf16len, char **utf8)
Definition: util.c:1280
#define uv__is_active(h)
Definition: uv-common.h:252
@ UV_CHANGE
Definition: uv.h:1542
@ UV_RENAME
Definition: uv.h:1541

References assert(), DWORD, err, file_info_cmp(), GET_REQ_ERROR, handle, L, loop, NULL, req, REQ_SUCCESS, uv__convert_utf16_to_utf8(), uv__free(), uv__is_active, uv__malloc(), UV_CHANGE, uv_fatal_error(), uv_fs_event_queue_readdirchanges(), UV_HANDLE_CLOSING, uv_relative_path(), UV_RENAME, uv_translate_sys_error(), and uv_want_endgame().

Referenced by uv_process_reqs().

◆ uv_process_pipe_accept_req()

void uv_process_pipe_accept_req ( uv_loop_t loop,
uv_pipe_t handle,
uv_req_t raw_req 
)

Definition at line 1910 of file pipe.c.

1911  {
1912  uv_pipe_accept_t* req = (uv_pipe_accept_t*) raw_req;
1913 
1914  assert(handle->type == UV_NAMED_PIPE);
1915 
1916  if (handle->flags & UV_HANDLE_CLOSING) {
1917  /* The req->pipeHandle should be freed already in uv_pipe_cleanup(). */
1918  assert(req->pipeHandle == INVALID_HANDLE_VALUE);
1920  return;
1921  }
1922 
1923  if (REQ_SUCCESS(req)) {
1924  assert(req->pipeHandle != INVALID_HANDLE_VALUE);
1925  req->next_pending = handle->pipe.serv.pending_accepts;
1926  handle->pipe.serv.pending_accepts = req;
1927 
1928  if (handle->stream.serv.connection_cb) {
1929  handle->stream.serv.connection_cb((uv_stream_t*)handle, 0);
1930  }
1931  } else {
1932  if (req->pipeHandle != INVALID_HANDLE_VALUE) {
1933  CloseHandle(req->pipeHandle);
1934  req->pipeHandle = INVALID_HANDLE_VALUE;
1935  }
1936  if (!(handle->flags & UV_HANDLE_CLOSING)) {
1938  }
1939  }
1940 
1942 }

References assert(), DECREASE_PENDING_REQ_COUNT, FALSE, handle, INVALID_HANDLE_VALUE, loop, req, REQ_SUCCESS, UV_HANDLE_CLOSING, and uv_pipe_queue_accept().

◆ uv_process_pipe_connect_req()

void uv_process_pipe_connect_req ( uv_loop_t loop,
uv_pipe_t handle,
uv_connect_t req 
)

Definition at line 1945 of file pipe.c.

1946  {
1947  int err;
1948 
1949  assert(handle->type == UV_NAMED_PIPE);
1950 
1952 
1953  if (req->cb) {
1954  err = 0;
1955  if (REQ_SUCCESS(req)) {
1957  } else {
1958  err = GET_REQ_ERROR(req);
1959  }
1961  }
1962 
1964 }

References assert(), DECREASE_PENDING_REQ_COUNT, err, GET_REQ_ERROR, handle, loop, req, REQ_SUCCESS, UNREGISTER_HANDLE_REQ, uv_pipe_connection_init(), and uv_translate_sys_error().

◆ uv_process_pipe_read_req()

void uv_process_pipe_read_req ( uv_loop_t loop,
uv_pipe_t handle,
uv_req_t req 
)

Definition at line 1789 of file pipe.c.

1791  {
1792  assert(handle->type == UV_NAMED_PIPE);
1793 
1797 
1798  /* At this point, we're done with bookkeeping. If the user has stopped
1799  * reading the pipe in the meantime, there is nothing left to do, since there
1800  * is no callback that we can call. */
1801  if (!(handle->flags & UV_HANDLE_READING))
1802  return;
1803 
1804  if (!REQ_SUCCESS(req)) {
1805  /* An error occurred doing the zero-read. */
1807 
1808  /* If the read was cancelled by uv__pipe_interrupt_read(), the request may
1809  * indicate an ERROR_OPERATION_ABORTED error. This error isn't relevant to
1810  * the user; we'll start a new zero-read at the end of this function. */
1811  if (err != ERROR_OPERATION_ABORTED)
1813 
1814  } else {
1815  /* The zero-read completed without error, indicating there is data
1816  * available in the kernel buffer. */
1817  DWORD avail;
1818 
1819  /* Get the number of bytes available. */
1820  avail = 0;
1821  if (!PeekNamedPipe(handle->handle, NULL, 0, NULL, &avail, NULL))
1823 
1824  /* Read until we've either read all the bytes available, or the 'reading'
1825  * flag is cleared. */
1826  while (avail > 0 && handle->flags & UV_HANDLE_READING) {
1827  /* Depending on the type of pipe, read either IPC frames or raw data. */
1828  DWORD bytes_read =
1830  : uv__pipe_read_data(loop, handle, avail, (DWORD) -1);
1831 
1832  /* If no bytes were read, treat this as an indication that an error
1833  * occurred, and break out of the read loop. */
1834  if (bytes_read == 0)
1835  break;
1836 
1837  /* It is possible that more bytes were read than we thought were
1838  * available. To prevent `avail` from underflowing, break out of the loop
1839  * if this is the case. */
1840  if (bytes_read > avail)
1841  break;
1842 
1843  /* Recompute the number of bytes available. */
1844  avail -= bytes_read;
1845  }
1846  }
1847 
1848  /* Start another zero-read request if necessary. */
1849  if ((handle->flags & UV_HANDLE_READING) &&
1850  !(handle->flags & UV_HANDLE_READ_PENDING)) {
1852  }
1853 }
static void eof_timer_stop(uv_pipe_t *pipe)
Definition: pipe.c:2022
static DWORD uv__pipe_read_data(uv_loop_t *loop, uv_pipe_t *handle, DWORD suggested_bytes, DWORD max_bytes)
Definition: pipe.c:1673
static void uv_pipe_read_error_or_eof(uv_loop_t *loop, uv_pipe_t *handle, int error, uv_buf_t buf)
Definition: pipe.c:1621
static DWORD uv__pipe_read_ipc(uv_loop_t *loop, uv_pipe_t *handle)
Definition: pipe.c:1708
static const uv_buf_t uv_null_buf_
Definition: pipe.c:42
@ UV_HANDLE_CANCELLATION_PENDING
Definition: uv-common.h:99

References assert(), DECREASE_PENDING_REQ_COUNT, DWORD, eof_timer_stop(), err, GET_REQ_ERROR, handle, loop, NULL, req, REQ_SUCCESS, uv__pipe_read_data(), uv__pipe_read_ipc(), UV_HANDLE_CANCELLATION_PENDING, UV_HANDLE_READ_PENDING, UV_HANDLE_READING, uv_null_buf_, uv_pipe_queue_read(), and uv_pipe_read_error_or_eof().

◆ uv_process_pipe_shutdown_req()

void uv_process_pipe_shutdown_req ( uv_loop_t loop,
uv_pipe_t handle,
uv_shutdown_t req 
)

Definition at line 1967 of file pipe.c.

1968  {
1969  assert(handle->type == UV_NAMED_PIPE);
1970 
1972 
1973  if (handle->flags & UV_HANDLE_READABLE) {
1974  /* Initialize and optionally start the eof timer. Only do this if the pipe
1975  * is readable and we haven't seen EOF come in ourselves. */
1977 
1978  /* If reading start the timer right now. Otherwise uv_pipe_queue_read will
1979  * start it. */
1980  if (handle->flags & UV_HANDLE_READ_PENDING) {
1982  }
1983 
1984  } else {
1985  /* This pipe is not readable. We can just close it to let the other end
1986  * know that we're done writing. */
1987  close_pipe(handle);
1988  }
1989 
1990  if (req->cb) {
1991  req->cb(req, 0);
1992  }
1993 
1995 }
static void eof_timer_init(uv_pipe_t *pipe)
Definition: pipe.c:1998
static void eof_timer_start(uv_pipe_t *pipe)
Definition: pipe.c:2013

References assert(), close_pipe(), DECREASE_PENDING_REQ_COUNT, eof_timer_init(), eof_timer_start(), handle, loop, req, UNREGISTER_HANDLE_REQ, UV_HANDLE_READ_PENDING, and UV_HANDLE_READABLE.

Referenced by uv_process_reqs().

◆ uv_process_pipe_write_req()

void uv_process_pipe_write_req ( uv_loop_t loop,
uv_pipe_t handle,
uv_write_t req 
)

Definition at line 1856 of file pipe.c.

1857  {
1858  int err;
1859 
1860  assert(handle->type == UV_NAMED_PIPE);
1861 
1862  assert(handle->write_queue_size >= req->u.io.queued_bytes);
1863  handle->write_queue_size -= req->u.io.queued_bytes;
1864 
1866 
1867  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
1868  if (req->wait_handle != INVALID_HANDLE_VALUE) {
1869  UnregisterWait(req->wait_handle);
1870  req->wait_handle = INVALID_HANDLE_VALUE;
1871  }
1872  if (req->event_handle) {
1873  CloseHandle(req->event_handle);
1874  req->event_handle = NULL;
1875  }
1876  }
1877 
1878  err = GET_REQ_ERROR(req);
1879 
1880  /* If this was a coalesced write, extract pointer to the user_provided
1881  * uv_write_t structure so we can pass the expected pointer to the callback,
1882  * then free the heap-allocated write req. */
1883  if (req->coalesced) {
1884  uv__coalesced_write_t* coalesced_write =
1886  req = coalesced_write->user_req;
1887  uv__free(coalesced_write);
1888  }
1889  if (req->cb) {
1891  }
1892 
1893  handle->stream.conn.write_reqs_pending--;
1894 
1895  if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE &&
1896  handle->pipe.conn.non_overlapped_writes_tail) {
1897  assert(handle->stream.conn.write_reqs_pending > 0);
1899  }
1900 
1901  if (handle->stream.conn.shutdown_req != NULL &&
1902  handle->stream.conn.write_reqs_pending == 0) {
1904  }
1905 
1907 }
#define container_of(ptr, type, member)
Definition: rz_types.h:650
uv_write_t * user_req
Definition: pipe.c:89
static void uv_queue_non_overlapped_write(uv_pipe_t *handle)
Definition: pipe.c:1240

References assert(), container_of, DECREASE_PENDING_REQ_COUNT, err, GET_REQ_ERROR, handle, INVALID_HANDLE_VALUE, loop, NULL, req, UNREGISTER_HANDLE_REQ, uv__coalesced_write_t::user_req, uv__free(), UV_HANDLE_EMULATE_IOCP, UV_HANDLE_NON_OVERLAPPED_PIPE, uv_queue_non_overlapped_write(), uv_translate_sys_error(), and uv_want_endgame().

◆ uv_process_poll_req()

void uv_process_poll_req ( uv_loop_t loop,
uv_poll_t handle,
uv_req_t req 
)

Definition at line 526 of file poll.c.

526  {
527  if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
529  } else {
531  }
532 }
static void uv__fast_poll_process_poll_req(uv_loop_t *loop, uv_poll_t *handle, uv_req_t *req)
Definition: poll.c:137
static void uv__slow_poll_process_poll_req(uv_loop_t *loop, uv_poll_t *handle, uv_req_t *req)
Definition: poll.c:366

References handle, loop, req, uv__fast_poll_process_poll_req(), uv__slow_poll_process_poll_req(), and UV_HANDLE_POLL_SLOW.

Referenced by uv_process_reqs().

◆ uv_process_proc_exit()

void uv_process_proc_exit ( uv_loop_t loop,
uv_process_t handle 
)

Definition at line 865 of file process.c.

865  {
866  int64_t exit_code;
867  DWORD status;
868 
869  assert(handle->exit_cb_pending);
870  handle->exit_cb_pending = 0;
871 
872  /* If we're closing, don't call the exit callback. Just schedule a close
873  * callback now. */
874  if (handle->flags & UV_HANDLE_CLOSING) {
876  return;
877  }
878 
879  /* Unregister from process notification. */
880  if (handle->wait_handle != INVALID_HANDLE_VALUE) {
881  UnregisterWait(handle->wait_handle);
882  handle->wait_handle = INVALID_HANDLE_VALUE;
883  }
884 
885  /* Set the handle to inactive: no callbacks will be made after the exit
886  * callback. */
888 
889  if (GetExitCodeProcess(handle->process_handle, &status)) {
890  exit_code = status;
891  } else {
892  /* Unable to obtain the exit code. This should never happen. */
893  exit_code = uv_translate_sys_error(GetLastError());
894  }
895 
896  /* Fire the exit callback. */
897  if (handle->exit_cb) {
898  handle->exit_cb(handle, exit_code, handle->exit_signal);
899  }
900 }
long int64_t
Definition: sftypes.h:32
#define uv__handle_stop(h)
Definition: uv-common.h:266

References assert(), DWORD, handle, INVALID_HANDLE_VALUE, loop, status, uv__handle_stop, UV_HANDLE_CLOSING, uv_translate_sys_error(), and uv_want_endgame().

Referenced by uv_process_reqs().

◆ uv_process_signal_req()

void uv_process_signal_req ( uv_loop_t loop,
uv_signal_t handle,
uv_req_t req 
)

Definition at line 234 of file signal.c.

235  {
236  long dispatched_signum;
237 
238  assert(handle->type == UV_SIGNAL);
239  assert(req->type == UV_SIGNAL_REQ);
240 
241  dispatched_signum = InterlockedExchange(
242  (volatile LONG*) &handle->pending_signum, 0);
243  assert(dispatched_signum != 0);
244 
245  /* Check if the pending signal equals the signum that we are watching for.
246  * These can get out of sync when the handler is stopped and restarted while
247  * the signal_req is pending. */
248  if (dispatched_signum == handle->signum)
249  handle->signal_cb(handle, dispatched_signum);
250 
251  if (handle->flags & UV_SIGNAL_ONE_SHOT)
253 
254  if (handle->flags & UV_HANDLE_CLOSING) {
255  /* When it is closing, it must be stopped at this point. */
256  assert(handle->signum == 0);
258  }
259 }
int uv_signal_stop(uv_signal_t *handle)
Definition: signal.c:513

References assert(), handle, InterlockedExchange, LONG, loop, req, UV_HANDLE_CLOSING, UV_SIGNAL_ONE_SHOT, uv_signal_stop(), and uv_want_endgame().

Referenced by uv_process_reqs().

◆ uv_process_tcp_accept_req()

void uv_process_tcp_accept_req ( uv_loop_t loop,
uv_tcp_t handle,
uv_req_t req 
)

Definition at line 1161 of file tcp.c.

1162  {
1163  uv_tcp_accept_t* req = (uv_tcp_accept_t*) raw_req;
1164  int err;
1165 
1166  assert(handle->type == UV_TCP);
1167 
1168  /* If handle->accepted_socket is not a valid socket, then uv_queue_accept
1169  * must have failed. This is a serious error. We stop accepting connections
1170  * and report this error to the connection callback. */
1171  if (req->accept_socket == INVALID_SOCKET) {
1172  if (handle->flags & UV_HANDLE_LISTENING) {
1173  handle->flags &= ~UV_HANDLE_LISTENING;
1175  if (handle->stream.serv.connection_cb) {
1177  handle->stream.serv.connection_cb((uv_stream_t*)handle,
1179  }
1180  }
1181  } else if (REQ_SUCCESS(req) &&
1182  setsockopt(req->accept_socket,
1183  SOL_SOCKET,
1184  SO_UPDATE_ACCEPT_CONTEXT,
1185  (char*)&handle->socket,
1186  sizeof(handle->socket)) == 0) {
1187  req->next_pending = handle->tcp.serv.pending_accepts;
1188  handle->tcp.serv.pending_accepts = req;
1189 
1190  /* Accept and SO_UPDATE_ACCEPT_CONTEXT were successful. */
1191  if (handle->stream.serv.connection_cb) {
1192  handle->stream.serv.connection_cb((uv_stream_t*)handle, 0);
1193  }
1194  } else {
1195  /* Error related to accepted socket is ignored because the server socket
1196  * may still be healthy. If the server socket is broken uv_queue_accept
1197  * will detect it. */
1198  closesocket(req->accept_socket);
1199  req->accept_socket = INVALID_SOCKET;
1200  if (handle->flags & UV_HANDLE_LISTENING) {
1202  }
1203  }
1204 
1206 }
#define GET_REQ_SOCK_ERROR(req)
Definition: req-inl.h:52
#define SOL_SOCKET
Definition: sftypes.h:427
static void uv_tcp_queue_accept(uv_tcp_t *handle, uv_tcp_accept_t *req)
Definition: tcp.c:393

References assert(), DECREASE_ACTIVE_COUNT, DECREASE_PENDING_REQ_COUNT, err, GET_REQ_SOCK_ERROR, handle, loop, req, REQ_SUCCESS, SOL_SOCKET, UV_HANDLE_LISTENING, uv_tcp_queue_accept(), and uv_translate_sys_error().

◆ uv_process_tcp_connect_req()

void uv_process_tcp_connect_req ( uv_loop_t loop,
uv_tcp_t handle,
uv_connect_t req 
)

Definition at line 1209 of file tcp.c.

1210  {
1211  int err;
1212 
1213  assert(handle->type == UV_TCP);
1214 
1216 
1217  err = 0;
1218  if (REQ_SUCCESS(req)) {
1219  if (handle->flags & UV_HANDLE_CLOSING) {
1220  /* use UV_ECANCELED for consistency with Unix */
1221  err = ERROR_OPERATION_ABORTED;
1222  } else if (setsockopt(handle->socket,
1223  SOL_SOCKET,
1225  NULL,
1226  0) == 0) {
1229  loop->active_tcp_streams++;
1230  } else {
1231  err = WSAGetLastError();
1232  }
1233  } else {
1235  }
1237 
1239 }
#define SO_UPDATE_CONNECT_CONTEXT
Definition: winsock.h:38

References assert(), DECREASE_PENDING_REQ_COUNT, err, GET_REQ_SOCK_ERROR, handle, loop, NULL, req, REQ_SUCCESS, SO_UPDATE_CONNECT_CONTEXT, SOL_SOCKET, UNREGISTER_HANDLE_REQ, uv_connection_init(), UV_HANDLE_CLOSING, UV_HANDLE_READABLE, UV_HANDLE_WRITABLE, and uv_translate_sys_error().

◆ uv_process_tcp_read_req()

void uv_process_tcp_read_req ( uv_loop_t loop,
uv_tcp_t handle,
uv_req_t req 
)

Definition at line 992 of file tcp.c.

993  {
994  DWORD bytes, flags, err;
995  uv_buf_t buf;
996  int count;
997 
998  assert(handle->type == UV_TCP);
999 
1000  handle->flags &= ~UV_HANDLE_READ_PENDING;
1001 
1002  if (!REQ_SUCCESS(req)) {
1003  /* An error occurred doing the read. */
1004  if ((handle->flags & UV_HANDLE_READING) ||
1005  !(handle->flags & UV_HANDLE_ZERO_READ)) {
1006  handle->flags &= ~UV_HANDLE_READING;
1008  buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
1009  uv_buf_init(NULL, 0) : handle->tcp.conn.read_buffer;
1010 
1012 
1013  if (err == WSAECONNABORTED) {
1014  /* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with Unix.
1015  */
1016  err = WSAECONNRESET;
1017  }
1018 
1019  handle->read_cb((uv_stream_t*)handle,
1021  &buf);
1022  }
1023  } else {
1024  if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
1025  /* The read was done with a non-zero buffer length. */
1026  if (req->u.io.overlapped.InternalHigh > 0) {
1027  /* Successful read */
1028  handle->read_cb((uv_stream_t*)handle,
1029  req->u.io.overlapped.InternalHigh,
1030  &handle->tcp.conn.read_buffer);
1031  /* Read again only if bytes == buf.len */
1032  if (req->u.io.overlapped.InternalHigh < handle->tcp.conn.read_buffer.len) {
1033  goto done;
1034  }
1035  } else {
1036  /* Connection closed */
1037  if (handle->flags & UV_HANDLE_READING) {
1038  handle->flags &= ~UV_HANDLE_READING;
1040  }
1041  handle->flags &= ~UV_HANDLE_READABLE;
1042 
1043  buf.base = 0;
1044  buf.len = 0;
1045  handle->read_cb((uv_stream_t*)handle, UV_EOF, &handle->tcp.conn.read_buffer);
1046  goto done;
1047  }
1048  }
1049 
1050  /* Do nonblocking reads until the buffer is empty */
1051  count = 32;
1052  while ((handle->flags & UV_HANDLE_READING) && (count-- > 0)) {
1053  buf = uv_buf_init(NULL, 0);
1054  handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
1055  if (buf.base == NULL || buf.len == 0) {
1056  handle->read_cb((uv_stream_t*) handle, UV_ENOBUFS, &buf);
1057  break;
1058  }
1059  assert(buf.base != NULL);
1060 
1061  flags = 0;
1062  if (WSARecv(handle->socket,
1063  (WSABUF*)&buf,
1064  1,
1065  &bytes,
1066  &flags,
1067  NULL,
1068  NULL) != SOCKET_ERROR) {
1069  if (bytes > 0) {
1070  /* Successful read */
1071  handle->read_cb((uv_stream_t*)handle, bytes, &buf);
1072  /* Read again only if bytes == buf.len */
1073  if (bytes < buf.len) {
1074  break;
1075  }
1076  } else {
1077  /* Connection closed */
1080 
1081  handle->read_cb((uv_stream_t*)handle, UV_EOF, &buf);
1082  break;
1083  }
1084  } else {
1085  err = WSAGetLastError();
1086  if (err == WSAEWOULDBLOCK) {
1087  /* Read buffer was completely empty, report a 0-byte read. */
1088  handle->read_cb((uv_stream_t*)handle, 0, &buf);
1089  } else {
1090  /* Ouch! serious error. */
1091  handle->flags &= ~UV_HANDLE_READING;
1093 
1094  if (err == WSAECONNABORTED) {
1095  /* Turn WSAECONNABORTED into UV_ECONNRESET to be consistent with
1096  * Unix. */
1097  err = WSAECONNRESET;
1098  }
1099 
1100  handle->read_cb((uv_stream_t*)handle,
1102  &buf);
1103  }
1104  break;
1105  }
1106  }
1107 
1108 done:
1109  /* Post another read if still reading and not closing. */
1110  if ((handle->flags & UV_HANDLE_READING) &&
1111  !(handle->flags & UV_HANDLE_READ_PENDING)) {
1113  }
1114  }
1115 
1117 }
struct tab * done
Definition: enough.c:233
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: unix.h:123
@ UV_HANDLE_ZERO_READ
Definition: uv-common.h:96
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
static void uv_tcp_queue_read(uv_loop_t *loop, uv_tcp_t *handle)
Definition: tcp.c:477

References assert(), bytes, count, DECREASE_ACTIVE_COUNT, DECREASE_PENDING_REQ_COUNT, done, DWORD, err, flags, GET_REQ_SOCK_ERROR, handle, loop, NULL, req, REQ_SUCCESS, uv_buf_init(), UV_HANDLE_READ_PENDING, UV_HANDLE_READABLE, UV_HANDLE_READING, UV_HANDLE_ZERO_READ, uv_tcp_queue_read(), and uv_translate_sys_error().

◆ uv_process_tcp_write_req()

void uv_process_tcp_write_req ( uv_loop_t loop,
uv_tcp_t handle,
uv_write_t req 
)

Definition at line 1120 of file tcp.c.

1121  {
1122  int err;
1123 
1124  assert(handle->type == UV_TCP);
1125 
1126  assert(handle->write_queue_size >= req->u.io.queued_bytes);
1127  handle->write_queue_size -= req->u.io.queued_bytes;
1128 
1130 
1131  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
1132  if (req->wait_handle != INVALID_HANDLE_VALUE) {
1133  UnregisterWait(req->wait_handle);
1134  req->wait_handle = INVALID_HANDLE_VALUE;
1135  }
1136  if (req->event_handle != NULL) {
1137  CloseHandle(req->event_handle);
1138  req->event_handle = NULL;
1139  }
1140  }
1141 
1142  if (req->cb) {
1144  if (err == UV_ECONNABORTED) {
1145  /* use UV_ECANCELED for consistency with Unix */
1146  err = UV_ECANCELED;
1147  }
1148  req->cb(req, err);
1149  }
1150 
1151  handle->stream.conn.write_reqs_pending--;
1152  if (handle->stream.conn.shutdown_req != NULL &&
1153  handle->stream.conn.write_reqs_pending == 0) {
1155  }
1156 
1158 }

References assert(), DECREASE_PENDING_REQ_COUNT, err, GET_REQ_SOCK_ERROR, handle, INVALID_HANDLE_VALUE, loop, NULL, req, UNREGISTER_HANDLE_REQ, UV_HANDLE_EMULATE_IOCP, uv_translate_sys_error(), and uv_want_endgame().

◆ uv_process_tty_accept_req()

void uv_process_tty_accept_req ( uv_loop_t loop,
uv_tty_t handle,
uv_req_t raw_req 
)

Definition at line 2308 of file tty.c.

2309  {
2310  abort();
2311 }

◆ uv_process_tty_connect_req()

void uv_process_tty_connect_req ( uv_loop_t loop,
uv_tty_t handle,
uv_connect_t req 
)

Definition at line 2318 of file tty.c.

2319  {
2320  abort();
2321 }

◆ uv_process_tty_read_req()

void uv_process_tty_read_req ( uv_loop_t loop,
uv_tty_t handle,
uv_req_t req 
)

Definition at line 1002 of file tty.c.

1003  {
1004  assert(handle->type == UV_TTY);
1006 
1007  /* If the read_line_buffer member is zero, it must have been an raw read.
1008  * Otherwise it was a line-buffered read. FIXME: This is quite obscure. Use a
1009  * flag or something. */
1010  if (handle->tty.rd.read_line_buffer.len == 0) {
1012  } else {
1014  }
1015 }
@ UV_HANDLE_TTY_READABLE
Definition: uv-common.h:122
void uv_process_tty_read_line_req(uv_loop_t *loop, uv_tty_t *handle, uv_req_t *req)
Definition: tty.c:960
void uv_process_tty_read_raw_req(uv_loop_t *loop, uv_tty_t *handle, uv_req_t *req)
Definition: tty.c:697

References assert(), handle, loop, req, UV_HANDLE_TTY_READABLE, uv_process_tty_read_line_req(), and uv_process_tty_read_raw_req().

◆ uv_process_tty_write_req()

void uv_process_tty_write_req ( uv_loop_t loop,
uv_tty_t handle,
uv_write_t req 
)

Definition at line 2227 of file tty.c.

2228  {
2229  int err;
2230 
2231  handle->write_queue_size -= req->u.io.queued_bytes;
2233 
2234  if (req->cb) {
2235  err = GET_REQ_ERROR(req);
2237  }
2238 
2239  handle->stream.conn.write_reqs_pending--;
2240  if (handle->stream.conn.shutdown_req != NULL &&
2241  handle->stream.conn.write_reqs_pending == 0) {
2243  }
2244 
2246 }

References DECREASE_PENDING_REQ_COUNT, err, GET_REQ_ERROR, handle, loop, NULL, req, UNREGISTER_HANDLE_REQ, uv_translate_sys_error(), and uv_want_endgame().

◆ uv_process_udp_recv_req()

void uv_process_udp_recv_req ( uv_loop_t loop,
uv_udp_t handle,
uv_req_t req 
)

Definition at line 453 of file udp.c.

454  {
455  uv_buf_t buf;
456  int partial;
457 
458  assert(handle->type == UV_UDP);
459 
460  handle->flags &= ~UV_HANDLE_READ_PENDING;
461 
462  if (!REQ_SUCCESS(req)) {
464  if (err == WSAEMSGSIZE) {
465  /* Not a real error, it just indicates that the received packet was
466  * bigger than the receive buffer. */
467  } else if (err == WSAECONNRESET || err == WSAENETRESET) {
468  /* A previous sendto operation failed; ignore this error. If zero-reading
469  * we need to call WSARecv/WSARecvFrom _without_ the. MSG_PEEK flag to
470  * clear out the error queue. For nonzero reads, immediately queue a new
471  * receive. */
472  if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
473  goto done;
474  }
475  } else {
476  /* A real error occurred. Report the error to the user only if we're
477  * currently reading. */
478  if (handle->flags & UV_HANDLE_READING) {
480  buf = (handle->flags & UV_HANDLE_ZERO_READ) ?
481  uv_buf_init(NULL, 0) : handle->recv_buffer;
482  handle->recv_cb(handle, uv_translate_sys_error(err), &buf, NULL, 0);
483  }
484  goto done;
485  }
486  }
487 
488  if (!(handle->flags & UV_HANDLE_ZERO_READ)) {
489  /* Successful read */
490  partial = !REQ_SUCCESS(req);
491  handle->recv_cb(handle,
492  req->u.io.overlapped.InternalHigh,
493  &handle->recv_buffer,
494  (const struct sockaddr*) &handle->recv_from,
495  partial ? UV_UDP_PARTIAL : 0);
496  } else if (handle->flags & UV_HANDLE_READING) {
497  DWORD bytes, err, flags;
498  struct sockaddr_storage from;
499  int from_len;
500 
501  /* Do a nonblocking receive.
502  * TODO: try to read multiple datagrams at once. FIONREAD maybe? */
503  buf = uv_buf_init(NULL, 0);
504  handle->alloc_cb((uv_handle_t*) handle, 65536, &buf);
505  if (buf.base == NULL || buf.len == 0) {
506  handle->recv_cb(handle, UV_ENOBUFS, &buf, NULL, 0);
507  goto done;
508  }
509  assert(buf.base != NULL);
510 
511  memset(&from, 0, sizeof from);
512  from_len = sizeof from;
513 
514  flags = 0;
515 
516  if (WSARecvFrom(handle->socket,
517  (WSABUF*)&buf,
518  1,
519  &bytes,
520  &flags,
521  (struct sockaddr*) &from,
522  &from_len,
523  NULL,
524  NULL) != SOCKET_ERROR) {
525 
526  /* Message received */
527  handle->recv_cb(handle, bytes, &buf, (const struct sockaddr*) &from, 0);
528  } else {
529  err = WSAGetLastError();
530  if (err == WSAEMSGSIZE) {
531  /* Message truncated */
532  handle->recv_cb(handle,
533  bytes,
534  &buf,
535  (const struct sockaddr*) &from,
537  } else if (err == WSAEWOULDBLOCK) {
538  /* Kernel buffer empty */
539  handle->recv_cb(handle, 0, &buf, NULL, 0);
540  } else if (err == WSAECONNRESET || err == WSAENETRESET) {
541  /* WSAECONNRESET/WSANETRESET is ignored because this just indicates
542  * that a previous sendto operation failed.
543  */
544  handle->recv_cb(handle, 0, &buf, NULL, 0);
545  } else {
546  /* Any other error that we want to report back to the user. */
548  handle->recv_cb(handle, uv_translate_sys_error(err), &buf, NULL, 0);
549  }
550  }
551  }
552 
553 done:
554  /* Post another read if still reading and not closing. */
555  if ((handle->flags & UV_HANDLE_READING) &&
556  !(handle->flags & UV_HANDLE_READ_PENDING)) {
558  }
559 
561 }
return memset(p, 0, total)
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
@ UV_UDP_PARTIAL
Definition: uv.h:602
UV_EXTERN int uv_udp_recv_stop(uv_udp_t *handle)
Definition: uv-common.c:478
static void uv_udp_queue_recv(uv_loop_t *loop, uv_udp_t *handle)
Definition: udp.c:267

References assert(), bytes, DECREASE_PENDING_REQ_COUNT, done, DWORD, err, flags, from, GET_REQ_SOCK_ERROR, handle, loop, memset(), NULL, req, REQ_SUCCESS, uv_buf_init(), UV_HANDLE_READ_PENDING, UV_HANDLE_READING, UV_HANDLE_ZERO_READ, uv_translate_sys_error(), UV_UDP_PARTIAL, uv_udp_queue_recv(), and uv_udp_recv_stop().

Referenced by uv_process_reqs().

◆ uv_process_udp_send_req()

void uv_process_udp_send_req ( uv_loop_t loop,
uv_udp_t handle,
uv_udp_send_t req 
)

Definition at line 564 of file udp.c.

565  {
566  int err;
567 
568  assert(handle->type == UV_UDP);
569 
570  assert(handle->send_queue_size >= req->u.io.queued_bytes);
571  assert(handle->send_queue_count >= 1);
572  handle->send_queue_size -= req->u.io.queued_bytes;
573  handle->send_queue_count--;
574 
576 
577  if (req->cb) {
578  err = 0;
579  if (!REQ_SUCCESS(req)) {
581  }
583  }
584 
586 }

References assert(), DECREASE_PENDING_REQ_COUNT, err, GET_REQ_SOCK_ERROR, handle, loop, req, REQ_SUCCESS, UNREGISTER_HANDLE_REQ, and uv_translate_sys_error().

Referenced by uv_process_reqs().

◆ uv_signal_close()

void uv_signal_close ( uv_loop_t loop,
uv_signal_t handle 
)

Definition at line 262 of file signal.c.

262  {
265 
266  if (handle->pending_signum == 0) {
268  }
269 }

References handle, loop, uv__handle_closing, uv_signal_stop(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_signal_endgame()

void uv_signal_endgame ( uv_loop_t loop,
uv_signal_t handle 
)

Definition at line 272 of file signal.c.

272  {
273  assert(handle->flags & UV_HANDLE_CLOSING);
274  assert(!(handle->flags & UV_HANDLE_CLOSED));
275 
276  assert(handle->signum == 0);
277  assert(handle->pending_signum == 0);
278 
279  handle->flags |= UV_HANDLE_CLOSED;
280 
282 }

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

Referenced by uv_process_endgames().

◆ uv_signals_init()

void uv_signals_init ( void  )

Definition at line 42 of file signal.c.

42  {
43  InitializeCriticalSection(&uv__signal_lock);
44  if (!SetConsoleCtrlHandler(uv__signal_control_handler, TRUE))
45  abort();
46 }
static BOOL WINAPI uv__signal_control_handler(DWORD type)
Definition: signal.c:116

References TRUE, uv__signal_control_handler(), and uv__signal_lock.

Referenced by uv_init().

◆ uv_stdio_pipe_server()

int uv_stdio_pipe_server ( uv_loop_t loop,
uv_pipe_t handle,
DWORD  access,
char *  name,
size_t  nameSize 
)

Definition at line 205 of file pipe.c.

206  {
207  HANDLE pipeHandle;
208  int err;
209  char* ptr = (char*)handle;
210 
211  for (;;) {
212  uv_unique_pipe_name(ptr, name, nameSize);
213 
214  pipeHandle = CreateNamedPipeA(name,
215  access | FILE_FLAG_OVERLAPPED | FILE_FLAG_FIRST_PIPE_INSTANCE | WRITE_DAC,
216  PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT, 1, 65536, 65536, 0,
217  NULL);
218 
219  if (pipeHandle != INVALID_HANDLE_VALUE) {
220  /* No name collisions. We're done. */
221  break;
222  }
223 
224  err = GetLastError();
225  if (err != ERROR_PIPE_BUSY && err != ERROR_ACCESS_DENIED) {
226  goto error;
227  }
228 
229  /* Pipe name collision. Increment the pointer and try again. */
230  ptr++;
231  }
232 
233  if (CreateIoCompletionPort(pipeHandle,
234  loop->iocp,
235  (ULONG_PTR)handle,
236  0) == NULL) {
237  err = GetLastError();
238  goto error;
239  }
240 
242  handle->handle = pipeHandle;
243 
244  return 0;
245 
246  error:
247  if (pipeHandle != INVALID_HANDLE_VALUE)
248  CloseHandle(pipeHandle);
249 
250  return err;
251 }
static void uv_unique_pipe_name(char *ptr, char *name, size_t size)
Definition: pipe.c:101

References access, err, error(), handle, HANDLE, INVALID_HANDLE_VALUE, loop, NULL, uv_pipe_connection_init(), and uv_unique_pipe_name().

Referenced by uv__create_stdio_pipe_pair().

◆ uv_tcp_accept()

int uv_tcp_accept ( uv_tcp_t server,
uv_tcp_t client 
)

Definition at line 657 of file tcp.c.

657  {
658  uv_loop_t* loop = server->loop;
659  int err = 0;
660  int family;
661 
662  uv_tcp_accept_t* req = server->tcp.serv.pending_accepts;
663 
664  if (!req) {
665  /* No valid connections found, so we error out. */
666  return WSAEWOULDBLOCK;
667  }
668 
669  if (req->accept_socket == INVALID_SOCKET) {
670  return WSAENOTCONN;
671  }
672 
673  if (server->flags & UV_HANDLE_IPV6) {
674  family = AF_INET6;
675  } else {
676  family = AF_INET;
677  }
678 
679  err = uv_tcp_set_socket(client->loop,
680  client,
681  req->accept_socket,
682  family,
683  0);
684  if (err) {
685  closesocket(req->accept_socket);
686  } else {
687  uv_connection_init((uv_stream_t*) client);
688  /* AcceptEx() implicitly binds the accepted socket. */
690  }
691 
692  /* Prepare the req to pick up a new connection */
693  server->tcp.serv.pending_accepts = req->next_pending;
694  req->next_pending = NULL;
695  req->accept_socket = INVALID_SOCKET;
696 
697  if (!(server->flags & UV_HANDLE_CLOSING)) {
698  /* Check if we're in a middle of changing the number of pending accepts. */
699  if (!(server->flags & UV_HANDLE_TCP_ACCEPT_STATE_CHANGING)) {
700  uv_tcp_queue_accept(server, req);
701  } else {
702  /* We better be switching to a single pending accept. */
703  assert(server->flags & UV_HANDLE_TCP_SINGLE_ACCEPT);
704 
705  server->tcp.serv.processed_accepts++;
706 
707  if (server->tcp.serv.processed_accepts >= uv_simultaneous_server_accepts) {
708  server->tcp.serv.processed_accepts = 0;
709  /*
710  * All previously queued accept requests are now processed.
711  * We now switch to queueing just a single accept.
712  */
713  uv_tcp_queue_accept(server, &server->tcp.serv.accept_reqs[0]);
714  server->flags &= ~UV_HANDLE_TCP_ACCEPT_STATE_CHANGING;
715  server->flags |= UV_HANDLE_TCP_SINGLE_ACCEPT;
716  }
717  }
718  }
719 
720  loop->active_tcp_streams++;
721 
722  return err;
723 }
#define AF_INET
Definition: sftypes.h:287
#define AF_INET6
Definition: sftypes.h:295
@ UV_HANDLE_IPV6
Definition: uv-common.h:102
@ UV_HANDLE_TCP_SINGLE_ACCEPT
Definition: uv-common.h:107
@ UV_HANDLE_TCP_ACCEPT_STATE_CHANGING
Definition: uv-common.h:108
const unsigned int uv_simultaneous_server_accepts
Definition: tcp.c:43

References AF_INET, AF_INET6, assert(), err, loop, NULL, req, uv_connection_init(), UV_HANDLE_BOUND, UV_HANDLE_CLOSING, UV_HANDLE_IPV6, UV_HANDLE_READABLE, UV_HANDLE_TCP_ACCEPT_STATE_CHANGING, UV_HANDLE_TCP_SINGLE_ACCEPT, UV_HANDLE_WRITABLE, uv_simultaneous_server_accepts, uv_tcp_queue_accept(), and uv_tcp_set_socket().

Referenced by uv_accept().

◆ uv_tcp_close()

void uv_tcp_close ( uv_loop_t loop,
uv_tcp_t tcp 
)

Definition at line 1426 of file tcp.c.

1426  {
1427  int close_socket = 1;
1428 
1429  if (tcp->flags & UV_HANDLE_READ_PENDING) {
1430  /* In order for winsock to do a graceful close there must not be any any
1431  * pending reads, or the socket must be shut down for writing */
1432  if (!(tcp->flags & UV_HANDLE_SHARED_TCP_SOCKET)) {
1433  /* Just do shutdown on non-shared sockets, which ensures graceful close. */
1434  shutdown(tcp->socket, SD_SEND);
1435 
1436  } else if (uv_tcp_try_cancel_io(tcp) == 0) {
1437  /* In case of a shared socket, we try to cancel all outstanding I/O,. If
1438  * that works, don't close the socket yet - wait for the read req to
1439  * return and close the socket in uv_tcp_endgame. */
1440  close_socket = 0;
1441 
1442  } else {
1443  /* When cancelling isn't possible - which could happen when an LSP is
1444  * present on an old Windows version, we will have to close the socket
1445  * with a read pending. That is not nice because trailing sent bytes may
1446  * not make it to the other side. */
1447  }
1448 
1449  } else if ((tcp->flags & UV_HANDLE_SHARED_TCP_SOCKET) &&
1450  tcp->tcp.serv.accept_reqs != NULL) {
1451  /* Under normal circumstances closesocket() will ensure that all pending
1452  * accept reqs are canceled. However, when the socket is shared the
1453  * presence of another reference to the socket in another process will keep
1454  * the accept reqs going, so we have to ensure that these are canceled. */
1455  if (uv_tcp_try_cancel_io(tcp) != 0) {
1456  /* When cancellation is not possible, there is another option: we can
1457  * close the incoming sockets, which will also cancel the accept
1458  * operations. However this is not cool because we might inadvertently
1459  * close a socket that just accepted a new connection, which will cause
1460  * the connection to be aborted. */
1461  unsigned int i;
1462  for (i = 0; i < uv_simultaneous_server_accepts; i++) {
1463  uv_tcp_accept_t* req = &tcp->tcp.serv.accept_reqs[i];
1464  if (req->accept_socket != INVALID_SOCKET &&
1465  !HasOverlappedIoCompleted(&req->u.io.overlapped)) {
1466  closesocket(req->accept_socket);
1467  req->accept_socket = INVALID_SOCKET;
1468  }
1469  }
1470  }
1471  }
1472 
1473  if (tcp->flags & UV_HANDLE_READING) {
1474  tcp->flags &= ~UV_HANDLE_READING;
1476  }
1477 
1478  if (tcp->flags & UV_HANDLE_LISTENING) {
1479  tcp->flags &= ~UV_HANDLE_LISTENING;
1481  }
1482 
1483  if (close_socket) {
1484  closesocket(tcp->socket);
1485  tcp->socket = INVALID_SOCKET;
1486  tcp->flags |= UV_HANDLE_TCP_SOCKET_CLOSED;
1487  }
1488 
1489  tcp->flags &= ~(UV_HANDLE_READABLE | UV_HANDLE_WRITABLE);
1490  uv__handle_closing(tcp);
1491 
1492  if (tcp->reqs_pending == 0) {
1493  uv_want_endgame(tcp->loop, (uv_handle_t*)tcp);
1494  }
1495 }
#define SD_SEND
Definition: rz_socket.h:41
@ UV_HANDLE_TCP_SOCKET_CLOSED
Definition: uv-common.h:109
static int uv_tcp_try_cancel_io(uv_tcp_t *tcp)
Definition: tcp.c:1389

References DECREASE_ACTIVE_COUNT, i, loop, NULL, req, SD_SEND, uv__handle_closing, UV_HANDLE_LISTENING, UV_HANDLE_READ_PENDING, UV_HANDLE_READABLE, UV_HANDLE_READING, UV_HANDLE_SHARED_TCP_SOCKET, UV_HANDLE_TCP_SOCKET_CLOSED, UV_HANDLE_WRITABLE, uv_simultaneous_server_accepts, uv_tcp_try_cancel_io(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_tcp_endgame()

void uv_tcp_endgame ( uv_loop_t loop,
uv_tcp_t handle 
)

Definition at line 208 of file tcp.c.

208  {
209  int err;
210  unsigned int i;
211  uv_tcp_accept_t* req;
212 
213  if (handle->flags & UV_HANDLE_CONNECTION &&
214  handle->stream.conn.shutdown_req != NULL &&
215  handle->stream.conn.write_reqs_pending == 0) {
216 
217  UNREGISTER_HANDLE_REQ(loop, handle, handle->stream.conn.shutdown_req);
218 
219  err = 0;
220  if (handle->flags & UV_HANDLE_CLOSING) {
221  err = ERROR_OPERATION_ABORTED;
222  } else if (shutdown(handle->socket, SD_SEND) == SOCKET_ERROR) {
223  err = WSAGetLastError();
224  }
225 
226  if (handle->stream.conn.shutdown_req->cb) {
227  handle->stream.conn.shutdown_req->cb(handle->stream.conn.shutdown_req,
229  }
230 
231  handle->stream.conn.shutdown_req = NULL;
233  return;
234  }
235 
236  if (handle->flags & UV_HANDLE_CLOSING &&
237  handle->reqs_pending == 0) {
238  assert(!(handle->flags & UV_HANDLE_CLOSED));
239 
240  if (!(handle->flags & UV_HANDLE_TCP_SOCKET_CLOSED)) {
241  closesocket(handle->socket);
242  handle->socket = INVALID_SOCKET;
244  }
245 
246  if (!(handle->flags & UV_HANDLE_CONNECTION) && handle->tcp.serv.accept_reqs) {
247  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
248  for (i = 0; i < uv_simultaneous_server_accepts; i++) {
249  req = &handle->tcp.serv.accept_reqs[i];
250  if (req->wait_handle != INVALID_HANDLE_VALUE) {
251  UnregisterWait(req->wait_handle);
252  req->wait_handle = INVALID_HANDLE_VALUE;
253  }
254  if (req->event_handle != NULL) {
255  CloseHandle(req->event_handle);
256  req->event_handle = NULL;
257  }
258  }
259  }
260 
261  uv__free(handle->tcp.serv.accept_reqs);
262  handle->tcp.serv.accept_reqs = NULL;
263  }
264 
265  if (handle->flags & UV_HANDLE_CONNECTION &&
266  handle->flags & UV_HANDLE_EMULATE_IOCP) {
267  if (handle->read_req.wait_handle != INVALID_HANDLE_VALUE) {
268  UnregisterWait(handle->read_req.wait_handle);
269  handle->read_req.wait_handle = INVALID_HANDLE_VALUE;
270  }
271  if (handle->read_req.event_handle != NULL) {
272  CloseHandle(handle->read_req.event_handle);
273  handle->read_req.event_handle = NULL;
274  }
275  }
276 
278  loop->active_tcp_streams--;
279  }
280 }

References assert(), DECREASE_PENDING_REQ_COUNT, err, handle, i, INVALID_HANDLE_VALUE, loop, NULL, req, SD_SEND, UNREGISTER_HANDLE_REQ, uv__free(), uv__handle_close, UV_HANDLE_CLOSED, UV_HANDLE_CLOSING, UV_HANDLE_CONNECTION, UV_HANDLE_EMULATE_IOCP, UV_HANDLE_TCP_SOCKET_CLOSED, uv_simultaneous_server_accepts, and uv_translate_sys_error().

Referenced by uv_process_endgames().

◆ uv_tcp_listen()

int uv_tcp_listen ( uv_tcp_t handle,
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
char * getenv()
static int maybe_new_socket(uv_tcp_t *handle, int domain, unsigned long flags)
Definition: tcp.c:67
#define uv__load_relaxed(p)
Definition: uv-common.h:67
#define uv__store_relaxed(p, v)
Definition: uv-common.h:68

References assert(), cb, err, handle, i, INCREASE_ACTIVE_COUNT, INVALID_HANDLE_VALUE, listen, loop, NULL, req, uv__malloc(), uv_addr_ip4_any_, uv_fatal_error(), uv_get_acceptex_function(), UV_HANDLE_BOUND, UV_HANDLE_EMULATE_IOCP, UV_HANDLE_LISTENING, UV_HANDLE_READING, UV_HANDLE_SHARED_TCP_SOCKET, UV_HANDLE_TCP_SINGLE_ACCEPT, UV_REQ_INIT, uv_simultaneous_server_accepts, uv_tcp_queue_accept(), and uv_tcp_try_bind().

◆ uv_tcp_read_start()

int uv_tcp_read_start ( uv_tcp_t handle,
uv_alloc_cb  alloc_cb,
uv_read_cb  read_cb 
)

Definition at line 726 of file tcp.c.

727  {
728  uv_loop_t* loop = handle->loop;
729 
730  handle->flags |= UV_HANDLE_READING;
731  handle->read_cb = read_cb;
732  handle->alloc_cb = alloc_cb;
734 
735  /* If reading was stopped and then started again, there could still be a read
736  * request pending. */
737  if (!(handle->flags & UV_HANDLE_READ_PENDING)) {
738  if (handle->flags & UV_HANDLE_EMULATE_IOCP &&
739  handle->read_req.event_handle == NULL) {
740  handle->read_req.event_handle = CreateEvent(NULL, 0, 0, NULL);
741  if (handle->read_req.event_handle == NULL) {
742  uv_fatal_error(GetLastError(), "CreateEvent");
743  }
744  }
746  }
747 
748  return 0;
749 }

References handle, INCREASE_ACTIVE_COUNT, loop, NULL, uv_fatal_error(), UV_HANDLE_EMULATE_IOCP, UV_HANDLE_READ_PENDING, UV_HANDLE_READING, and uv_tcp_queue_read().

Referenced by uv_read_start().

◆ uv_tcp_write()

int uv_tcp_write ( uv_loop_t loop,
uv_write_t req,
uv_tcp_t handle,
const uv_buf_t  bufs[],
unsigned int  nbufs,
uv_write_cb  cb 
)

Definition at line 901 of file tcp.c.

906  {
907  int result;
908  DWORD bytes;
909 
910  UV_REQ_INIT(req, UV_WRITE);
911  req->handle = (uv_stream_t*) handle;
912  req->cb = cb;
913 
914  /* Prepare the overlapped structure. */
915  memset(&(req->u.io.overlapped), 0, sizeof(req->u.io.overlapped));
916  if (handle->flags & UV_HANDLE_EMULATE_IOCP) {
917  req->event_handle = CreateEvent(NULL, 0, 0, NULL);
918  if (req->event_handle == NULL) {
919  uv_fatal_error(GetLastError(), "CreateEvent");
920  }
921  req->u.io.overlapped.hEvent = (HANDLE) ((ULONG_PTR) req->event_handle | 1);
922  req->wait_handle = INVALID_HANDLE_VALUE;
923  }
924 
925  result = WSASend(handle->socket,
926  (WSABUF*) bufs,
927  nbufs,
928  &bytes,
929  0,
930  &req->u.io.overlapped,
931  NULL);
932 
933  if (UV_SUCCEEDED_WITHOUT_IOCP(result == 0)) {
934  /* Request completed immediately. */
935  req->u.io.queued_bytes = 0;
936  handle->reqs_pending++;
937  handle->stream.conn.write_reqs_pending++;
940  } else if (UV_SUCCEEDED_WITH_IOCP(result == 0)) {
941  /* Request queued by the kernel. */
942  req->u.io.queued_bytes = uv__count_bufs(bufs, nbufs);
943  handle->reqs_pending++;
944  handle->stream.conn.write_reqs_pending++;
946  handle->write_queue_size += req->u.io.queued_bytes;
947  if (handle->flags & UV_HANDLE_EMULATE_IOCP &&
948  !RegisterWaitForSingleObject(&req->wait_handle,
949  req->event_handle, post_write_completion, (void*) req,
950  INFINITE, WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE)) {
951  SET_REQ_ERROR(req, GetLastError());
953  }
954  } else {
955  /* Send failed due to an error, report it later */
956  req->u.io.queued_bytes = 0;
957  handle->reqs_pending++;
958  handle->stream.conn.write_reqs_pending++;
960  SET_REQ_ERROR(req, WSAGetLastError());
962  }
963 
964  return 0;
965 }
#define UV_SUCCEEDED_WITH_IOCP(result)
Definition: req-inl.h:72
#define REGISTER_HANDLE_REQ(loop, handle, req)
Definition: req-inl.h:56
#define UV_SUCCEEDED_WITHOUT_IOCP(result)
Definition: req-inl.h:69
#define SET_REQ_ERROR(req, error)
Definition: req-inl.h:34
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:322
static void CALLBACK post_write_completion(void *context, BOOLEAN timed_out)
Definition: tcp.c:374

References bufs, bytes, cb, DWORD, handle, HANDLE, INVALID_HANDLE_VALUE, loop, memset(), NULL, post_write_completion(), REGISTER_HANDLE_REQ, req, SET_REQ_ERROR, uv__count_bufs(), uv_fatal_error(), UV_HANDLE_EMULATE_IOCP, uv_insert_pending_req(), UV_REQ_INIT, UV_SUCCEEDED_WITH_IOCP, and UV_SUCCEEDED_WITHOUT_IOCP.

Referenced by uv_write().

◆ uv_translate_sys_error()

int uv_translate_sys_error ( int  sys_errno)

Definition at line 1249 of file core.c.

1249  {
1250  /* If < 0 then it's already a libuv error. */
1251  return sys_errno <= 0 ? sys_errno : -sys_errno;
1252 }

References ERROR_ELEVATION_REQUIRED, and ERROR_SYMLINK_NOT_SUPPORTED.

Referenced by uv__getsockpeername(), uv__socket_sockopt(), and uv_loop_init().

◆ uv_tty_close()

void uv_tty_close ( uv_tty_t handle)

Definition at line 2249 of file tty.c.

2249  {
2250  assert(handle->u.fd == -1 || handle->u.fd > 2);
2251  if (handle->flags & UV_HANDLE_READING)
2253 
2254  if (handle->u.fd == -1)
2255  CloseHandle(handle->handle);
2256  else
2257  close(handle->u.fd);
2258 
2259  handle->u.fd = -1;
2260  handle->handle = INVALID_HANDLE_VALUE;
2263 
2264  if (handle->reqs_pending == 0) {
2266  }
2267 }
static static fork const void static count close
Definition: sflib.h:33
int uv_tty_read_stop(uv_tty_t *handle)
Definition: tty.c:1054

References assert(), close, handle, INVALID_HANDLE_VALUE, uv__handle_closing, UV_HANDLE_READABLE, UV_HANDLE_READING, UV_HANDLE_WRITABLE, uv_tty_read_stop(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_tty_endgame()

void uv_tty_endgame ( uv_loop_t loop,
uv_tty_t handle 
)

Definition at line 2270 of file tty.c.

2270  {
2271  if (!(handle->flags & UV_HANDLE_TTY_READABLE) &&
2272  handle->stream.conn.shutdown_req != NULL &&
2273  handle->stream.conn.write_reqs_pending == 0) {
2274  UNREGISTER_HANDLE_REQ(loop, handle, handle->stream.conn.shutdown_req);
2275 
2276  /* TTY shutdown is really just a no-op */
2277  if (handle->stream.conn.shutdown_req->cb) {
2278  if (handle->flags & UV_HANDLE_CLOSING) {
2279  handle->stream.conn.shutdown_req->cb(handle->stream.conn.shutdown_req, UV_ECANCELED);
2280  } else {
2281  handle->stream.conn.shutdown_req->cb(handle->stream.conn.shutdown_req, 0);
2282  }
2283  }
2284 
2285  handle->stream.conn.shutdown_req = NULL;
2286 
2288  return;
2289  }
2290 
2291  if (handle->flags & UV_HANDLE_CLOSING &&
2292  handle->reqs_pending == 0) {
2293  /* The wait handle used for raw reading should be unregistered when the
2294  * wait callback runs. */
2295  assert(!(handle->flags & UV_HANDLE_TTY_READABLE) ||
2296  handle->tty.rd.read_raw_wait == NULL);
2297 
2298  assert(!(handle->flags & UV_HANDLE_CLOSED));
2300  }
2301 }

References assert(), DECREASE_PENDING_REQ_COUNT, handle, loop, NULL, UNREGISTER_HANDLE_REQ, uv__handle_close, UV_HANDLE_CLOSED, UV_HANDLE_CLOSING, and UV_HANDLE_TTY_READABLE.

Referenced by uv_process_endgames().

◆ uv_tty_read_start()

int uv_tty_read_start ( uv_tty_t handle,
uv_alloc_cb  alloc_cb,
uv_read_cb  read_cb 
)

Definition at line 1018 of file tty.c.

1019  {
1020  uv_loop_t* loop = handle->loop;
1021 
1022  if (!(handle->flags & UV_HANDLE_TTY_READABLE)) {
1023  return ERROR_INVALID_PARAMETER;
1024  }
1025 
1026  handle->flags |= UV_HANDLE_READING;
1028  handle->read_cb = read_cb;
1029  handle->alloc_cb = alloc_cb;
1030 
1031  /* If reading was stopped and then started again, there could still be a read
1032  * request pending. */
1033  if (handle->flags & UV_HANDLE_READ_PENDING) {
1034  return 0;
1035  }
1036 
1037  /* Maybe the user stopped reading half-way while processing key events.
1038  * Short-circuit if this could be the case. */
1039  if (handle->tty.rd.last_key_len > 0) {
1040  SET_REQ_SUCCESS(&handle->read_req);
1041  uv_insert_pending_req(handle->loop, (uv_req_t*) &handle->read_req);
1042  /* Make sure no attempt is made to insert it again until it's handled. */
1043  handle->flags |= UV_HANDLE_READ_PENDING;
1044  handle->reqs_pending++;
1045  return 0;
1046  }
1047 
1049 
1050  return 0;
1051 }
#define SET_REQ_SUCCESS(req)
Definition: req-inl.h:40
static void uv_tty_queue_read(uv_loop_t *loop, uv_tty_t *handle)
Definition: tty.c:622

References handle, INCREASE_ACTIVE_COUNT, loop, SET_REQ_SUCCESS, UV_HANDLE_READ_PENDING, UV_HANDLE_READING, UV_HANDLE_TTY_READABLE, uv_insert_pending_req(), and uv_tty_queue_read().

Referenced by uv_read_start(), and uv_tty_set_mode().

◆ uv_tty_read_stop()

int uv_tty_read_stop ( uv_tty_t handle)

Definition at line 1054 of file tty.c.

1054  {
1055  INPUT_RECORD record;
1056  DWORD written, err;
1057 
1058  handle->flags &= ~UV_HANDLE_READING;
1060 
1061  if (!(handle->flags & UV_HANDLE_READ_PENDING))
1062  return 0;
1063 
1064  if (handle->flags & UV_HANDLE_TTY_RAW) {
1065  /* Cancel raw read. Write some bullshit event to force the console wait to
1066  * return. */
1067  memset(&record, 0, sizeof record);
1068  record.EventType = FOCUS_EVENT;
1069  if (!WriteConsoleInputW(handle->handle, &record, 1, &written)) {
1070  return GetLastError();
1071  }
1072  } else if (!(handle->flags & UV_HANDLE_CANCELLATION_PENDING)) {
1073  /* Cancel line-buffered read if not already pending */
1075  if (err)
1076  return err;
1077 
1079  }
1080 
1081  return 0;
1082 }
Definition: tar.h:52
@ UV_HANDLE_TTY_RAW
Definition: uv-common.h:123
static int uv__cancel_read_console(uv_tty_t *handle)
Definition: tty.c:1084

References DECREASE_ACTIVE_COUNT, DWORD, err, handle, memset(), uv__cancel_read_console(), UV_HANDLE_CANCELLATION_PENDING, UV_HANDLE_READ_PENDING, UV_HANDLE_READING, and UV_HANDLE_TTY_RAW.

Referenced by uv_read_stop(), uv_tty_close(), and uv_tty_set_mode().

◆ uv_tty_write()

int uv_tty_write ( uv_loop_t loop,
uv_write_t req,
uv_tty_t handle,
const uv_buf_t  bufs[],
unsigned int  nbufs,
uv_write_cb  cb 
)

Definition at line 2182 of file tty.c.

2187  {
2188  DWORD error;
2189 
2190  UV_REQ_INIT(req, UV_WRITE);
2191  req->handle = (uv_stream_t*) handle;
2192  req->cb = cb;
2193 
2194  handle->reqs_pending++;
2195  handle->stream.conn.write_reqs_pending++;
2197 
2198  req->u.io.queued_bytes = 0;
2199 
2200  if (!uv_tty_write_bufs(handle, bufs, nbufs, &error)) {
2202  } else {
2204  }
2205 
2207 
2208  return 0;
2209 }

References bufs, cb, DWORD, error(), handle, loop, REGISTER_HANDLE_REQ, req, SET_REQ_ERROR, SET_REQ_SUCCESS, uv_insert_pending_req(), UV_REQ_INIT, and uv_tty_write_bufs().

Referenced by uv_write().

◆ uv_udp_close()

void uv_udp_close ( uv_loop_t loop,
uv_udp_t handle 
)

Definition at line 170 of file udp.c.

170  {
172  closesocket(handle->socket);
173  handle->socket = INVALID_SOCKET;
174 
176 
177  if (handle->reqs_pending == 0) {
179  }
180 }

References handle, loop, uv__handle_closing, uv_udp_recv_stop(), and uv_want_endgame().

Referenced by uv_close().

◆ uv_udp_endgame()

void uv_udp_endgame ( uv_loop_t loop,
uv_udp_t handle 
)

Definition at line 183 of file udp.c.

183  {
184  if (handle->flags & UV_HANDLE_CLOSING &&
185  handle->reqs_pending == 0) {
186  assert(!(handle->flags & UV_HANDLE_CLOSED));
188  }
189 }

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

Referenced by uv_process_endgames().

◆ uv_winapi_init()

void uv_winapi_init ( void  )

Definition at line 49 of file winapi.c.

49  {
50  HMODULE ntdll_module;
51  HMODULE powrprof_module;
52  HMODULE user32_module;
53  HMODULE kernel32_module;
54 
55  ntdll_module = GetModuleHandleA("ntdll.dll");
56  if (ntdll_module == NULL) {
57  uv_fatal_error(GetLastError(), "GetModuleHandleA");
58  }
59 
60  pRtlGetVersion = (sRtlGetVersion) GetProcAddress(ntdll_module,
61  "RtlGetVersion");
62 
64  ntdll_module,
65  "RtlNtStatusToDosError");
67  uv_fatal_error(GetLastError(), "GetProcAddress");
68  }
69 
71  ntdll_module,
72  "NtDeviceIoControlFile");
74  uv_fatal_error(GetLastError(), "GetProcAddress");
75  }
76 
78  ntdll_module,
79  "NtQueryInformationFile");
81  uv_fatal_error(GetLastError(), "GetProcAddress");
82  }
83 
85  ntdll_module,
86  "NtSetInformationFile");
87  if (pNtSetInformationFile == NULL) {
88  uv_fatal_error(GetLastError(), "GetProcAddress");
89  }
90 
92  GetProcAddress(ntdll_module, "NtQueryVolumeInformationFile");
94  uv_fatal_error(GetLastError(), "GetProcAddress");
95  }
96 
98  GetProcAddress(ntdll_module, "NtQueryDirectoryFile");
100  uv_fatal_error(GetLastError(), "GetProcAddress");
101  }
102 
104  ntdll_module,
105  "NtQuerySystemInformation");
107  uv_fatal_error(GetLastError(), "GetProcAddress");
108  }
109 
111  ntdll_module,
112  "NtQueryInformationProcess");
114  uv_fatal_error(GetLastError(), "GetProcAddress");
115  }
116 
117  kernel32_module = GetModuleHandleA("kernel32.dll");
118  if (kernel32_module == NULL) {
119  uv_fatal_error(GetLastError(), "GetModuleHandleA");
120  }
121 
123  kernel32_module,
124  "GetQueuedCompletionStatusEx");
125 
126  powrprof_module = LoadLibraryA("powrprof.dll");
127  if (powrprof_module != NULL) {
129  GetProcAddress(powrprof_module, "PowerRegisterSuspendResumeNotification");
130  }
131 
132  user32_module = LoadLibraryA("user32.dll");
133  if (user32_module != NULL) {
135  GetProcAddress(user32_module, "SetWinEventHook");
136  }
137 }
sNtQueryVolumeInformationFile pNtQueryVolumeInformationFile
Definition: winapi.c:34
sNtQueryDirectoryFile pNtQueryDirectoryFile
Definition: winapi.c:35
sNtQueryInformationProcess pNtQueryInformationProcess
Definition: winapi.c:37
sGetQueuedCompletionStatusEx pGetQueuedCompletionStatusEx
Definition: winapi.c:40
sRtlGetVersion pRtlGetVersion
Definition: winapi.c:29
sNtSetInformationFile pNtSetInformationFile
Definition: winapi.c:33
sSetWinEventHook pSetWinEventHook
Definition: winapi.c:46
sNtQuerySystemInformation pNtQuerySystemInformation
Definition: winapi.c:36
sPowerRegisterSuspendResumeNotification pPowerRegisterSuspendResumeNotification
Definition: winapi.c:43
HWINEVENTHOOK(WINAPI * sSetWinEventHook)(UINT eventMin, UINT eventMax, HMODULE hmodWinEventProc, WINEVENTPROC lpfnWinEventProc, DWORD idProcess, DWORD idThread, UINT dwflags)
Definition: winapi.h:4721
BOOL(WINAPI * sGetQueuedCompletionStatusEx)(HANDLE CompletionPort, LPOVERLAPPED_ENTRY lpCompletionPortEntries, ULONG ulCount, PULONG ulNumEntriesRemoved, DWORD dwMilliseconds, BOOL fAlertable)
Definition: winapi.h:4670
NTSTATUS(NTAPI * sNtSetInformationFile)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass)
Definition: winapi.h:4559
NTSTATUS(NTAPI * sRtlGetVersion)(PRTL_OSVERSIONINFOW lpVersionInformation)
Definition: winapi.h:4534
NTSTATUS(NTAPI * sNtQueryInformationProcess)(HANDLE ProcessHandle, UINT ProcessInformationClass, PVOID ProcessInformation, ULONG Length, PULONG ReturnLength)
Definition: winapi.h:4593
ULONG(NTAPI * sRtlNtStatusToDosError)(NTSTATUS Status)
Definition: winapi.h:4537
NTSTATUS(NTAPI * sNtQueryInformationFile)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass)
Definition: winapi.h:4552
DWORD(WINAPI * sPowerRegisterSuspendResumeNotification)(DWORD Flags, HANDLE Recipient, _PHPOWERNOTIFY RegistrationHandle)
Definition: winapi.h:4706
NTSTATUS(NTAPI * sNtQueryVolumeInformationFile)(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
Definition: winapi.h:4566
NTSTATUS(NTAPI * sNtQueryDirectoryFile)(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, ULONG Length, FILE_INFORMATION_CLASS FileInformationClass, BOOLEAN ReturnSingleEntry, PUNICODE_STRING FileName, BOOLEAN RestartScan)
Definition: winapi.h:4579
NTSTATUS(NTAPI * sNtDeviceIoControlFile)(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG IoControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
Definition: winapi.h:4540
NTSTATUS(NTAPI * sNtQuerySystemInformation)(UINT SystemInformationClass, PVOID SystemInformation, ULONG SystemInformationLength, PULONG ReturnLength)
Definition: winapi.h:4573

References NULL, pGetQueuedCompletionStatusEx, pNtDeviceIoControlFile, pNtQueryDirectoryFile, pNtQueryInformationFile, pNtQueryInformationProcess, pNtQuerySystemInformation, pNtQueryVolumeInformationFile, pNtSetInformationFile, pPowerRegisterSuspendResumeNotification, pRtlGetVersion, pRtlNtStatusToDosError, pSetWinEventHook, and uv_fatal_error().

Referenced by uv_init().

◆ uv_winsock_init()

void uv_winsock_init ( void  )

Definition at line 78 of file winsock.c.

78  {
79  WSADATA wsa_data;
80  int errorno;
81  SOCKET dummy;
82  WSAPROTOCOL_INFOW protocol_info;
83  int opt_len;
84 
85  /* Set implicit binding address used by connectEx */
86  if (uv_ip4_addr("0.0.0.0", 0, &uv_addr_ip4_any_)) {
87  abort();
88  }
89 
90  if (uv_ip6_addr("::", 0, &uv_addr_ip6_any_)) {
91  abort();
92  }
93 
94  /* Skip initialization in safe mode without network support */
95  if (1 == GetSystemMetrics(SM_CLEANBOOT)) return;
96 
97  /* Initialize winsock */
98  errorno = WSAStartup(MAKEWORD(2, 2), &wsa_data);
99  if (errorno != 0) {
100  uv_fatal_error(errorno, "WSAStartup");
101  }
102 
103  /* Try to detect non-IFS LSPs */
105  dummy = socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
106  if (dummy != INVALID_SOCKET) {
107  opt_len = (int) sizeof protocol_info;
108  if (getsockopt(dummy,
109  SOL_SOCKET,
110  SO_PROTOCOL_INFOW,
111  (char*) &protocol_info,
112  &opt_len) == 0) {
113  if (protocol_info.dwServiceFlags1 & XP1_IFS_HANDLES)
115  }
116  closesocket(dummy);
117  }
118 
119  /* Try to detect IPV6 support and non-IFS LSPs */
121  dummy = socket(AF_INET6, SOCK_STREAM, IPPROTO_IP);
122  if (dummy != INVALID_SOCKET) {
123  opt_len = (int) sizeof protocol_info;
124  if (getsockopt(dummy,
125  SOL_SOCKET,
126  SO_PROTOCOL_INFOW,
127  (char*) &protocol_info,
128  &opt_len) == 0) {
129  if (protocol_info.dwServiceFlags1 & XP1_IFS_HANDLES)
131  }
132  closesocket(dummy);
133  }
134 }
static int
Definition: sfsocketcall.h:114
@ SOCK_STREAM
Definition: sftypes.h:224
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
Definition: uv-common.c:221
UV_EXTERN int uv_ip6_addr(const char *ip, int port, struct sockaddr_in6 *addr)
Definition: uv-common.c:232
struct sockaddr_in uv_addr_ip4_any_
Definition: winsock.c:34
int uv_tcp_non_ifs_lsp_ipv4
Definition: winsock.c:30
int uv_tcp_non_ifs_lsp_ipv6
Definition: winsock.c:31
struct sockaddr_in6 uv_addr_ip6_any_
Definition: winsock.c:35

References AF_INET, AF_INET6, int, SOCK_STREAM, socket, SOL_SOCKET, uv_addr_ip4_any_, uv_addr_ip6_any_, uv_fatal_error(), uv_ip4_addr(), uv_ip6_addr(), uv_tcp_non_ifs_lsp_ipv4, and uv_tcp_non_ifs_lsp_ipv6.

Referenced by uv_init().

◆ uv_wsarecv_workaround()

int WSAAPI uv_wsarecv_workaround ( SOCKET  socket,
WSABUF *  buffers,
DWORD  buffer_count,
DWORD bytes,
DWORD flags,
WSAOVERLAPPED *  overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE  completion_routine 
)

Definition at line 270 of file winsock.c.

272  {
274  void* apc_context;
275  IO_STATUS_BLOCK* iosb = (IO_STATUS_BLOCK*) &overlapped->Internal;
277  DWORD error;
278 
279  if (overlapped == NULL || completion_routine != NULL) {
280  WSASetLastError(WSAEINVAL);
281  return SOCKET_ERROR;
282  }
283 
284  info.BufferArray = buffers;
285  info.BufferCount = buffer_count;
286  info.AfdFlags = AFD_OVERLAPPED;
287  info.TdiFlags = TDI_RECEIVE_NORMAL;
288 
289  if (*flags & MSG_PEEK) {
290  info.TdiFlags |= TDI_RECEIVE_PEEK;
291  }
292 
293  if (*flags & MSG_PARTIAL) {
294  info.TdiFlags |= TDI_RECEIVE_PARTIAL;
295  }
296 
297  if (!((intptr_t) overlapped->hEvent & 1)) {
298  apc_context = (void*) overlapped;
299  } else {
300  apc_context = NULL;
301  }
302 
303  iosb->Status = STATUS_PENDING;
304  iosb->Pointer = 0;
305 
307  overlapped->hEvent,
308  NULL,
309  apc_context,
310  iosb,
312  &info,
313  sizeof(info),
314  NULL,
315  0);
316 
317  *flags = 0;
318  *bytes = (DWORD) iosb->Information;
319 
320  switch (status) {
321  case STATUS_SUCCESS:
322  error = ERROR_SUCCESS;
323  break;
324 
325  case STATUS_PENDING:
326  error = WSA_IO_PENDING;
327  break;
328 
330  error = WSAEMSGSIZE;
331  break;
332 
334  error = ERROR_SUCCESS;
335  *flags = MSG_OOB;
336  break;
337 
339  error = ERROR_SUCCESS;
340  *flags = MSG_PARTIAL | MSG_OOB;
341  break;
342 
344  error = ERROR_SUCCESS;
345  *flags = MSG_PARTIAL;
346  break;
347 
348  default:
350  break;
351  }
352 
353  WSASetLastError(error);
354 
355  if (error == ERROR_SUCCESS) {
356  return 0;
357  } else {
358  return SOCKET_ERROR;
359  }
360 }
RzBinInfo * info(RzBinFile *bf)
Definition: bin_ne.c:86
_W64 signed int intptr_t
ULONG_PTR Information
Definition: winapi.h:4168
#define STATUS_RECEIVE_EXPEDITED
Definition: winapi.h:356
#define STATUS_RECEIVE_PARTIAL
Definition: winapi.h:352
#define STATUS_RECEIVE_PARTIAL_EXPEDITED
Definition: winapi.h:360
#define TDI_RECEIVE_PARTIAL
Definition: winsock.h:72
#define AFD_OVERLAPPED
Definition: winsock.h:93
#define TDI_RECEIVE_PEEK
Definition: winsock.h:75
#define TDI_RECEIVE_NORMAL
Definition: winsock.h:73
#define IOCTL_AFD_RECEIVE
Definition: winsock.h:148

References AFD_OVERLAPPED, bytes, DWORD, error(), flags, HANDLE, if(), info(), _IO_STATUS_BLOCK::Information, IOCTL_AFD_RECEIVE, NULL, pNtDeviceIoControlFile, _IO_STATUS_BLOCK::Pointer, socket, status, _IO_STATUS_BLOCK::Status, STATUS_BUFFER_OVERFLOW, STATUS_PENDING, STATUS_RECEIVE_EXPEDITED, STATUS_RECEIVE_PARTIAL, STATUS_RECEIVE_PARTIAL_EXPEDITED, STATUS_SUCCESS, TDI_RECEIVE_NORMAL, TDI_RECEIVE_PARTIAL, TDI_RECEIVE_PEEK, and uv_ntstatus_to_winsock_error().

Referenced by uv_udp_set_socket().

◆ uv_wsarecvfrom_workaround()

int WSAAPI uv_wsarecvfrom_workaround ( SOCKET  socket,
WSABUF *  buffers,
DWORD  buffer_count,
DWORD bytes,
DWORD flags,
struct sockaddr addr,
int addr_len,
WSAOVERLAPPED *  overlapped,
LPWSAOVERLAPPED_COMPLETION_ROUTINE  completion_routine 
)

Definition at line 364 of file winsock.c.

367  {
369  void* apc_context;
370  IO_STATUS_BLOCK* iosb = (IO_STATUS_BLOCK*) &overlapped->Internal;
372  DWORD error;
373 
374  if (overlapped == NULL || addr == NULL || addr_len == NULL ||
375  completion_routine != NULL) {
376  WSASetLastError(WSAEINVAL);
377  return SOCKET_ERROR;
378  }
379 
380  info.BufferArray = buffers;
381  info.BufferCount = buffer_count;
382  info.AfdFlags = AFD_OVERLAPPED;
383  info.TdiFlags = TDI_RECEIVE_NORMAL;
384  info.Address = addr;
385  info.AddressLength = addr_len;
386 
387  if (*flags & MSG_PEEK) {
388  info.TdiFlags |= TDI_RECEIVE_PEEK;
389  }
390 
391  if (*flags & MSG_PARTIAL) {
392  info.TdiFlags |= TDI_RECEIVE_PARTIAL;
393  }
394 
395  if (!((intptr_t) overlapped->hEvent & 1)) {
396  apc_context = (void*) overlapped;
397  } else {
398  apc_context = NULL;
399  }
400 
401  iosb->Status = STATUS_PENDING;
402  iosb->Pointer = 0;
403 
405  overlapped->hEvent,
406  NULL,
407  apc_context,
408  iosb,
410  &info,
411  sizeof(info),
412  NULL,
413  0);
414 
415  *flags = 0;
416  *bytes = (DWORD) iosb->Information;
417 
418  switch (status) {
419  case STATUS_SUCCESS:
420  error = ERROR_SUCCESS;
421  break;
422 
423  case STATUS_PENDING:
424  error = WSA_IO_PENDING;
425  break;
426 
428  error = WSAEMSGSIZE;
429  break;
430 
432  error = ERROR_SUCCESS;
433  *flags = MSG_OOB;
434  break;
435 
437  error = ERROR_SUCCESS;
438  *flags = MSG_PARTIAL | MSG_OOB;
439  break;
440 
442  error = ERROR_SUCCESS;
443  *flags = MSG_PARTIAL;
444  break;
445 
446  default:
448  break;
449  }
450 
451  WSASetLastError(error);
452 
453  if (error == ERROR_SUCCESS) {
454  return 0;
455  } else {
456  return SOCKET_ERROR;
457  }
458 }
#define IOCTL_AFD_RECEIVE_DATAGRAM
Definition: winsock.h:151
static int addr
Definition: z80asm.c:58

References addr, AFD_OVERLAPPED, bytes, DWORD, error(), flags, HANDLE, if(), info(), _IO_STATUS_BLOCK::Information, IOCTL_AFD_RECEIVE_DATAGRAM, NULL, pNtDeviceIoControlFile, _IO_STATUS_BLOCK::Pointer, socket, status, _IO_STATUS_BLOCK::Status, STATUS_BUFFER_OVERFLOW, STATUS_PENDING, STATUS_RECEIVE_EXPEDITED, STATUS_RECEIVE_PARTIAL, STATUS_RECEIVE_PARTIAL_EXPEDITED, STATUS_SUCCESS, TDI_RECEIVE_NORMAL, TDI_RECEIVE_PARTIAL, TDI_RECEIVE_PEEK, and uv_ntstatus_to_winsock_error().

Referenced by uv_udp_set_socket().

Variable Documentation

◆ syscall

◆ uv_addr_ip4_any_

◆ uv_addr_ip6_any_

◆ uv_tcp_non_ifs_lsp_ipv4

int uv_tcp_non_ifs_lsp_ipv4
extern

Definition at line 30 of file winsock.c.

Referenced by uv_tcp_set_socket(), uv_tcp_try_cancel_io(), and uv_winsock_init().

◆ uv_tcp_non_ifs_lsp_ipv6

int uv_tcp_non_ifs_lsp_ipv6
extern

Definition at line 31 of file winsock.c.

Referenced by uv_tcp_set_socket(), uv_tcp_try_cancel_io(), and uv_winsock_init().