Rizin
unix-like reverse engineering framework and cli tools
poll.c File Reference
#include <assert.h>
#include <io.h>
#include "uv.h"
#include "internal.h"
#include "handle-inl.h"
#include "req-inl.h"

Go to the source code of this file.

Classes

struct  uv_single_fd_set_s
 

Typedefs

typedef struct uv_single_fd_set_s uv_single_fd_set_t
 

Functions

static void uv__init_overlapped_dummy (void)
 
static OVERLAPPED * uv__get_overlapped_dummy (void)
 
static AFD_POLL_INFOuv__get_afd_poll_info_dummy (void)
 
static void uv__fast_poll_submit_poll_req (uv_loop_t *loop, uv_poll_t *handle)
 
static void uv__fast_poll_process_poll_req (uv_loop_t *loop, uv_poll_t *handle, uv_req_t *req)
 
static SOCKET uv__fast_poll_create_peer_socket (HANDLE iocp, WSAPROTOCOL_INFOW *protocol_info)
 
static SOCKET uv__fast_poll_get_peer_socket (uv_loop_t *loop, WSAPROTOCOL_INFOW *protocol_info)
 
static DWORD WINAPI uv__slow_poll_thread_proc (void *arg)
 
static void uv__slow_poll_submit_poll_req (uv_loop_t *loop, uv_poll_t *handle)
 
static void uv__slow_poll_process_poll_req (uv_loop_t *loop, uv_poll_t *handle, uv_req_t *req)
 
int uv_poll_init (uv_loop_t *loop, uv_poll_t *handle, int fd)
 
int uv_poll_init_socket (uv_loop_t *loop, uv_poll_t *handle, uv_os_sock_t socket)
 
static int uv__poll_set (uv_poll_t *handle, int events, uv_poll_cb cb)
 
int uv_poll_start (uv_poll_t *handle, int events, uv_poll_cb cb)
 
int uv_poll_stop (uv_poll_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)
 

Variables

static const GUID uv_msafd_provider_ids [UV_MSAFD_PROVIDER_COUNT]
 
static OVERLAPPED overlapped_dummy_
 
static uv_once_t overlapped_dummy_init_guard_ = UV_ONCE_INIT
 
static AFD_POLL_INFO afd_poll_info_dummy_
 

Typedef Documentation

◆ uv_single_fd_set_t

Function Documentation

◆ uv__fast_poll_create_peer_socket()

static SOCKET uv__fast_poll_create_peer_socket ( HANDLE  iocp,
WSAPROTOCOL_INFOW *  protocol_info 
)
static

Definition at line 203 of file poll.c.

204  {
205  SOCKET sock = 0;
206 
207  sock = WSASocketW(protocol_info->iAddressFamily,
208  protocol_info->iSocketType,
209  protocol_info->iProtocol,
210  protocol_info,
211  0,
212  WSA_FLAG_OVERLAPPED);
213  if (sock == INVALID_SOCKET) {
214  return INVALID_SOCKET;
215  }
216 
217  if (!SetHandleInformation((HANDLE) sock, HANDLE_FLAG_INHERIT, 0)) {
218  goto error;
219  };
220 
221  if (CreateIoCompletionPort((HANDLE) sock,
222  iocp,
223  (ULONG_PTR) sock,
224  0) == NULL) {
225  goto error;
226  }
227 
228  return sock;
229 
230  error:
231  closesocket(sock);
232  return INVALID_SOCKET;
233 }
#define NULL
Definition: cris-opc.c:27
void error(const char *msg)
Definition: untgz.c:593
DWORD * HANDLE

References error(), HANDLE, and NULL.

Referenced by uv__fast_poll_get_peer_socket().

◆ uv__fast_poll_get_peer_socket()

static SOCKET uv__fast_poll_get_peer_socket ( uv_loop_t loop,
WSAPROTOCOL_INFOW *  protocol_info 
)
static

Definition at line 236 of file poll.c.

237  {
238  int index, i;
239  SOCKET peer_socket;
240 
241  index = -1;
242  for (i = 0; (size_t) i < ARRAY_SIZE(uv_msafd_provider_ids); i++) {
243  if (memcmp((void*) &protocol_info->ProviderId,
244  (void*) &uv_msafd_provider_ids[i],
245  sizeof protocol_info->ProviderId) == 0) {
246  index = i;
247  }
248  }
249 
250  /* Check if the protocol uses an msafd socket. */
251  if (index < 0) {
252  return INVALID_SOCKET;
253  }
254 
255  /* If we didn't (try) to create a peer socket yet, try to make one. Don't try
256  * again if the peer socket creation failed earlier for the same protocol. */
257  peer_socket = loop->poll_peer_sockets[index];
258  if (peer_socket == 0) {
259  peer_socket = uv__fast_poll_create_peer_socket(loop->iocp, protocol_info);
260  loop->poll_peer_sockets[index] = peer_socket;
261  }
262 
263  return peer_socket;
264 }
#define ARRAY_SIZE(a)
lzma_index ** i
Definition: index.h:629
int size_t
Definition: sftypes.h:40
uv_loop_t * loop
Definition: main.c:7
static const GUID uv_msafd_provider_ids[UV_MSAFD_PROVIDER_COUNT]
Definition: poll.c:31
static SOCKET uv__fast_poll_create_peer_socket(HANDLE iocp, WSAPROTOCOL_INFOW *protocol_info)
Definition: poll.c:203

References ARRAY_SIZE, i, loop, uv__fast_poll_create_peer_socket(), and uv_msafd_provider_ids.

Referenced by uv_poll_init_socket().

◆ uv__fast_poll_process_poll_req()

static void uv__fast_poll_process_poll_req ( uv_loop_t loop,
uv_poll_t handle,
uv_req_t req 
)
static

Definition at line 137 of file poll.c.

138  {
139  unsigned char mask_events;
140  AFD_POLL_INFO* afd_poll_info;
141 
142  if (req == &handle->poll_req_1) {
143  afd_poll_info = &handle->afd_poll_info_1;
144  handle->submitted_events_1 = 0;
145  mask_events = handle->mask_events_1;
146  } else if (req == &handle->poll_req_2) {
147  afd_poll_info = &handle->afd_poll_info_2;
148  handle->submitted_events_2 = 0;
149  mask_events = handle->mask_events_2;
150  } else {
151  assert(0);
152  return;
153  }
154 
155  /* Report an error unless the select was just interrupted. */
156  if (!REQ_SUCCESS(req)) {
158  if (error != WSAEINTR && handle->events != 0) {
159  handle->events = 0; /* Stop the watcher */
160  handle->poll_cb(handle, uv_translate_sys_error(error), 0);
161  }
162 
163  } else if (afd_poll_info->NumberOfHandles >= 1) {
164  unsigned char events = 0;
165 
166  if ((afd_poll_info->Handles[0].Events & (AFD_POLL_RECEIVE |
168  events |= UV_READABLE;
169  if ((afd_poll_info->Handles[0].Events & AFD_POLL_DISCONNECT) != 0) {
170  events |= UV_DISCONNECT;
171  }
172  }
173  if ((afd_poll_info->Handles[0].Events & (AFD_POLL_SEND |
174  AFD_POLL_CONNECT_FAIL)) != 0) {
175  events |= UV_WRITABLE;
176  }
177 
178  events &= handle->events & ~mask_events;
179 
180  if (afd_poll_info->Handles[0].Events & AFD_POLL_LOCAL_CLOSE) {
181  /* Stop polling. */
182  handle->events = 0;
183  if (uv__is_active(handle))
185  }
186 
187  if (events != 0) {
188  handle->poll_cb(handle, 0, events);
189  }
190  }
191 
192  if ((handle->events & ~(handle->submitted_events_1 |
193  handle->submitted_events_2)) != 0) {
195  } else if ((handle->flags & UV_HANDLE_CLOSING) &&
196  handle->submitted_events_1 == 0 &&
197  handle->submitted_events_2 == 0) {
199  }
200 }
static mcore_handle handle
Definition: asm_mcore.c:8
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
static INLINE void uv_want_endgame(uv_loop_t *loop, uv_handle_t *handle)
Definition: handle-inl.h:88
assert(limit<=UINT32_MAX/2)
#define REQ_SUCCESS(req)
Definition: req-inl.h:46
#define GET_REQ_SOCK_ERROR(req)
Definition: req-inl.h:52
ULONG NumberOfHandles
Definition: win.h:214
AFD_POLL_HANDLE_INFO Handles[1]
Definition: win.h:216
@ UV_HANDLE_CLOSING
Definition: uv-common.h:74
#define uv__handle_stop(h)
Definition: uv-common.h:266
#define uv__is_active(h)
Definition: uv-common.h:252
UV_EXTERN int uv_translate_sys_error(int sys_errno)
Definition: core.c:1249
@ UV_WRITABLE
Definition: uv.h:801
@ UV_DISCONNECT
Definition: uv.h:802
@ UV_READABLE
Definition: uv.h:800
static void uv__fast_poll_submit_poll_req(uv_loop_t *loop, uv_poll_t *handle)
Definition: poll.c:75
DWORD
#define AFD_POLL_CONNECT_FAIL
Definition: winsock.h:113
#define AFD_POLL_ABORT
Definition: winsock.h:105
#define AFD_POLL_RECEIVE
Definition: winsock.h:97
#define AFD_POLL_DISCONNECT
Definition: winsock.h:103
#define AFD_POLL_ACCEPT
Definition: winsock.h:111
#define AFD_POLL_LOCAL_CLOSE
Definition: winsock.h:107
#define AFD_POLL_SEND
Definition: winsock.h:101

References AFD_POLL_ABORT, AFD_POLL_ACCEPT, AFD_POLL_CONNECT_FAIL, AFD_POLL_DISCONNECT, AFD_POLL_LOCAL_CLOSE, AFD_POLL_RECEIVE, AFD_POLL_SEND, assert(), DWORD, error(), _AFD_POLL_HANDLE_INFO::Events, GET_REQ_SOCK_ERROR, handle, _AFD_POLL_INFO::Handles, loop, _AFD_POLL_INFO::NumberOfHandles, req, REQ_SUCCESS, uv__fast_poll_submit_poll_req(), uv__handle_stop, uv__is_active, UV_DISCONNECT, UV_HANDLE_CLOSING, UV_READABLE, uv_translate_sys_error(), uv_want_endgame(), and UV_WRITABLE.

Referenced by uv_process_poll_req().

◆ uv__fast_poll_submit_poll_req()

static void uv__fast_poll_submit_poll_req ( uv_loop_t loop,
uv_poll_t handle 
)
static

Definition at line 75 of file poll.c.

75  {
76  uv_req_t* req;
77  AFD_POLL_INFO* afd_poll_info;
78  int result;
79 
80  /* Find a yet unsubmitted req to submit. */
81  if (handle->submitted_events_1 == 0) {
82  req = &handle->poll_req_1;
83  afd_poll_info = &handle->afd_poll_info_1;
84  handle->submitted_events_1 = handle->events;
85  handle->mask_events_1 = 0;
86  handle->mask_events_2 = handle->events;
87  } else if (handle->submitted_events_2 == 0) {
88  req = &handle->poll_req_2;
89  afd_poll_info = &handle->afd_poll_info_2;
90  handle->submitted_events_2 = handle->events;
91  handle->mask_events_1 = handle->events;
92  handle->mask_events_2 = 0;
93  } else {
94  /* Just wait until there's an unsubmitted req. This will happen almost
95  * immediately as one of the 2 outstanding requests is about to return.
96  * When this happens, uv__fast_poll_process_poll_req will be called, and
97  * the pending events, if needed, will be processed in a subsequent
98  * request. */
99  return;
100  }
101 
102  /* Setting Exclusive to TRUE makes the other poll request return if there is
103  * any. */
104  afd_poll_info->Exclusive = TRUE;
105  afd_poll_info->NumberOfHandles = 1;
106  afd_poll_info->Timeout.QuadPart = INT64_MAX;
107  afd_poll_info->Handles[0].Handle = (HANDLE) handle->socket;
108  afd_poll_info->Handles[0].Status = 0;
109  afd_poll_info->Handles[0].Events = 0;
110 
111  if (handle->events & UV_READABLE) {
112  afd_poll_info->Handles[0].Events |= AFD_POLL_RECEIVE |
114  } else {
115  if (handle->events & UV_DISCONNECT) {
116  afd_poll_info->Handles[0].Events |= AFD_POLL_DISCONNECT;
117  }
118  }
119  if (handle->events & UV_WRITABLE) {
120  afd_poll_info->Handles[0].Events |= AFD_POLL_SEND | AFD_POLL_CONNECT_FAIL;
121  }
122 
123  memset(&req->u.io.overlapped, 0, sizeof req->u.io.overlapped);
124 
125  result = uv_msafd_poll((SOCKET) handle->peer_socket,
126  afd_poll_info,
127  afd_poll_info,
128  &req->u.io.overlapped);
129  if (result != 0 && WSAGetLastError() != WSA_IO_PENDING) {
130  /* Queue this req, reporting an error. */
131  SET_REQ_ERROR(req, WSAGetLastError());
133  }
134 }
return memset(p, 0, total)
#define TRUE
Definition: mybfd.h:103
static INLINE void uv_insert_pending_req(uv_loop_t *loop, uv_req_t *req)
Definition: req-inl.h:90
#define SET_REQ_ERROR(req, error)
Definition: req-inl.h:34
#define INT64_MAX
NTSTATUS Status
Definition: win.h:209
LARGE_INTEGER Timeout
Definition: win.h:213
ULONG Exclusive
Definition: win.h:215
Definition: uv.h:407
int WSAAPI uv_msafd_poll(SOCKET socket, AFD_POLL_INFO *info_in, AFD_POLL_INFO *info_out, OVERLAPPED *overlapped)
Definition: winsock.c:461
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References AFD_POLL_ABORT, AFD_POLL_ACCEPT, AFD_POLL_CONNECT_FAIL, AFD_POLL_DISCONNECT, AFD_POLL_RECEIVE, AFD_POLL_SEND, _AFD_POLL_HANDLE_INFO::Events, _AFD_POLL_INFO::Exclusive, handle, HANDLE, _AFD_POLL_HANDLE_INFO::Handle, _AFD_POLL_INFO::Handles, if(), INT64_MAX, loop, memset(), _AFD_POLL_INFO::NumberOfHandles, req, SET_REQ_ERROR, _AFD_POLL_HANDLE_INFO::Status, _AFD_POLL_INFO::Timeout, TRUE, UV_DISCONNECT, uv_insert_pending_req(), uv_msafd_poll(), UV_READABLE, and UV_WRITABLE.

Referenced by uv__fast_poll_process_poll_req(), and uv__poll_set().

◆ uv__get_afd_poll_info_dummy()

static AFD_POLL_INFO* uv__get_afd_poll_info_dummy ( void  )
static

Definition at line 70 of file poll.c.

70  {
71  return &afd_poll_info_dummy_;
72 }
static AFD_POLL_INFO afd_poll_info_dummy_
Definition: poll.c:49

References afd_poll_info_dummy_.

Referenced by uv_poll_close().

◆ uv__get_overlapped_dummy()

static OVERLAPPED* uv__get_overlapped_dummy ( void  )
static

Definition at line 64 of file poll.c.

64  {
66  return &overlapped_dummy_;
67 }
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419
static void uv__init_overlapped_dummy(void)
Definition: poll.c:52
static OVERLAPPED overlapped_dummy_
Definition: poll.c:46
static uv_once_t overlapped_dummy_init_guard_
Definition: poll.c:47

References overlapped_dummy_, overlapped_dummy_init_guard_, uv__init_overlapped_dummy(), and uv_once().

Referenced by uv_poll_close().

◆ uv__init_overlapped_dummy()

static void uv__init_overlapped_dummy ( void  )
static

Definition at line 52 of file poll.c.

52  {
53  HANDLE event;
54 
55  event = CreateEvent(NULL, TRUE, TRUE, NULL);
56  if (event == NULL)
57  uv_fatal_error(GetLastError(), "CreateEvent");
58 
60  overlapped_dummy_.hEvent = (HANDLE) ((uintptr_t) event | 1);
61 }
void uv_fatal_error(const int errorno, const char *syscall)
Definition: error.c:35
_W64 unsigned int uintptr_t

References HANDLE, memset(), NULL, overlapped_dummy_, TRUE, and uv_fatal_error().

Referenced by uv__get_overlapped_dummy().

◆ uv__poll_set()

static int uv__poll_set ( uv_poll_t handle,
int  events,
uv_poll_cb  cb 
)
static

Definition at line 486 of file poll.c.

486  {
487  int submitted_events;
488 
489  assert(handle->type == UV_POLL);
490  assert(!(handle->flags & UV_HANDLE_CLOSING));
491  assert((events & ~(UV_READABLE | UV_WRITABLE | UV_DISCONNECT)) == 0);
492 
493  handle->events = events;
494  handle->poll_cb = cb;
495 
496  if (handle->events == 0) {
498  return 0;
499  }
500 
502  submitted_events = handle->submitted_events_1 | handle->submitted_events_2;
503 
504  if (handle->events & ~submitted_events) {
505  if (handle->flags & UV_HANDLE_POLL_SLOW) {
507  } else {
509  }
510  }
511 
512  return 0;
513 }
@ UV_HANDLE_POLL_SLOW
Definition: uv-common.h:132
#define uv__handle_start(h)
Definition: uv-common.h:258
static void uv__slow_poll_submit_poll_req(uv_loop_t *loop, uv_poll_t *handle)
Definition: poll.c:336
static const char * cb[]
Definition: z80_tab.h:176

References assert(), cb, handle, uv__fast_poll_submit_poll_req(), uv__handle_start, uv__handle_stop, uv__slow_poll_submit_poll_req(), UV_DISCONNECT, UV_HANDLE_CLOSING, UV_HANDLE_POLL_SLOW, UV_READABLE, and UV_WRITABLE.

Referenced by uv_poll_start(), and uv_poll_stop().

◆ uv__slow_poll_process_poll_req()

static void uv__slow_poll_process_poll_req ( uv_loop_t loop,
uv_poll_t handle,
uv_req_t req 
)
static

Definition at line 366 of file poll.c.

367  {
368  unsigned char mask_events;
369  int err;
370 
371  if (req == &handle->poll_req_1) {
372  handle->submitted_events_1 = 0;
373  mask_events = handle->mask_events_1;
374  } else if (req == &handle->poll_req_2) {
375  handle->submitted_events_2 = 0;
376  mask_events = handle->mask_events_2;
377  } else {
378  assert(0);
379  return;
380  }
381 
382  if (!REQ_SUCCESS(req)) {
383  /* Error. */
384  if (handle->events != 0) {
385  err = GET_REQ_ERROR(req);
386  handle->events = 0; /* Stop the watcher */
387  handle->poll_cb(handle, uv_translate_sys_error(err), 0);
388  }
389  } else {
390  /* Got some events. */
391  int events = req->u.io.overlapped.InternalHigh & handle->events & ~mask_events;
392  if (events != 0) {
393  handle->poll_cb(handle, 0, events);
394  }
395  }
396 
397  if ((handle->events & ~(handle->submitted_events_1 |
398  handle->submitted_events_2)) != 0) {
400  } else if ((handle->flags & UV_HANDLE_CLOSING) &&
401  handle->submitted_events_1 == 0 &&
402  handle->submitted_events_2 == 0) {
404  }
405 }
static bool err
Definition: armass.c:435
#define GET_REQ_ERROR(req)
Definition: req-inl.h:49

References assert(), err, GET_REQ_ERROR, handle, loop, req, REQ_SUCCESS, uv__slow_poll_submit_poll_req(), UV_HANDLE_CLOSING, uv_translate_sys_error(), and uv_want_endgame().

Referenced by uv_process_poll_req().

◆ uv__slow_poll_submit_poll_req()

static void uv__slow_poll_submit_poll_req ( uv_loop_t loop,
uv_poll_t handle 
)
static

Definition at line 336 of file poll.c.

336  {
337  uv_req_t* req;
338 
339  /* Find a yet unsubmitted req to submit. */
340  if (handle->submitted_events_1 == 0) {
341  req = &handle->poll_req_1;
342  handle->submitted_events_1 = handle->events;
343  handle->mask_events_1 = 0;
344  handle->mask_events_2 = handle->events;
345  } else if (handle->submitted_events_2 == 0) {
346  req = &handle->poll_req_2;
347  handle->submitted_events_2 = handle->events;
348  handle->mask_events_1 = handle->events;
349  handle->mask_events_2 = 0;
350  } else {
351  assert(0);
352  return;
353  }
354 
355  if (!QueueUserWorkItem(uv__slow_poll_thread_proc,
356  (void*) req,
357  WT_EXECUTELONGFUNCTION)) {
358  /* Make this req pending, reporting an error. */
359  SET_REQ_ERROR(req, GetLastError());
361  }
362 }
static DWORD WINAPI uv__slow_poll_thread_proc(void *arg)
Definition: poll.c:267

References assert(), handle, loop, req, SET_REQ_ERROR, uv__slow_poll_thread_proc(), and uv_insert_pending_req().

Referenced by uv__poll_set(), and uv__slow_poll_process_poll_req().

◆ uv__slow_poll_thread_proc()

static DWORD WINAPI uv__slow_poll_thread_proc ( void *  arg)
static

Definition at line 267 of file poll.c.

267  {
268  uv_req_t* req = (uv_req_t*) arg;
269  uv_poll_t* handle = (uv_poll_t*) req->data;
270  unsigned char reported_events;
271  int r;
272  uv_single_fd_set_t rfds, wfds, efds;
273  struct timeval timeout;
274 
275  assert(handle->type == UV_POLL);
276  assert(req->type == UV_POLL_REQ);
277 
278  if (handle->events & UV_READABLE) {
279  rfds.fd_count = 1;
280  rfds.fd_array[0] = handle->socket;
281  } else {
282  rfds.fd_count = 0;
283  }
284 
285  if (handle->events & UV_WRITABLE) {
286  wfds.fd_count = 1;
287  wfds.fd_array[0] = handle->socket;
288  efds.fd_count = 1;
289  efds.fd_array[0] = handle->socket;
290  } else {
291  wfds.fd_count = 0;
292  efds.fd_count = 0;
293  }
294 
295  /* Make the select() time out after 3 minutes. If select() hangs because the
296  * user closed the socket, we will at least not hang indefinitely. */
297  timeout.tv_sec = 3 * 60;
298  timeout.tv_usec = 0;
299 
300  r = select(1, (fd_set*) &rfds, (fd_set*) &wfds, (fd_set*) &efds, &timeout);
301  if (r == SOCKET_ERROR) {
302  /* Queue this req, reporting an error. */
303  SET_REQ_ERROR(&handle->poll_req_1, WSAGetLastError());
305  return 0;
306  }
307 
308  reported_events = 0;
309 
310  if (r > 0) {
311  if (rfds.fd_count > 0) {
312  assert(rfds.fd_count == 1);
313  assert(rfds.fd_array[0] == handle->socket);
314  reported_events |= UV_READABLE;
315  }
316 
317  if (wfds.fd_count > 0) {
318  assert(wfds.fd_count == 1);
319  assert(wfds.fd_array[0] == handle->socket);
320  reported_events |= UV_WRITABLE;
321  } else if (efds.fd_count > 0) {
322  assert(efds.fd_count == 1);
323  assert(efds.fd_array[0] == handle->socket);
324  reported_events |= UV_WRITABLE;
325  }
326  }
327 
329  req->u.io.overlapped.InternalHigh = (DWORD) reported_events;
331 
332  return 0;
333 }
#define r
Definition: crypto_rc6.c:12
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz select
Definition: sflib.h:108
#define SET_REQ_SUCCESS(req)
Definition: req-inl.h:40
#define POST_COMPLETION_FOR_REQ(loop, req)
Definition: req-inl.h:76
Definition: uv.h:793
uv_timer_t timeout
Definition: main.c:9

References assert(), DWORD, handle, POST_COMPLETION_FOR_REQ, r, req, select, SET_REQ_ERROR, SET_REQ_SUCCESS, timeout, UV_READABLE, and UV_WRITABLE.

Referenced by uv__slow_poll_submit_poll_req().

◆ 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 uv__handle_closing(handle)
Definition: handle-inl.h:63
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 }
#define uv__handle_close(handle)
Definition: handle-inl.h:76
@ 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_poll_init()

int uv_poll_init ( uv_loop_t loop,
uv_poll_t handle,
int  fd 
)

Definition at line 408 of file poll.c.

408  {
409  return uv_poll_init_socket(loop, handle, (SOCKET) uv__get_osfhandle(fd));
410 }
static INLINE HANDLE uv__get_osfhandle(int fd)
Definition: handle-inl.h:166
int uv_poll_init_socket(uv_loop_t *loop, uv_poll_t *handle, uv_os_sock_t socket)
Definition: poll.c:96
static const z80_opcode fd[]
Definition: z80_tab.h:997

References err, fd, handle, loop, NULL, uv__fd_exists(), uv__get_osfhandle(), uv__handle_init, uv__io_check_fd(), uv__io_init(), uv__nonblock, uv__nonblock_fcntl(), uv__nonblock_ioctl(), uv__poll_io(), and uv_poll_init_socket().

◆ uv_poll_init_socket()

int uv_poll_init_socket ( uv_loop_t loop,
uv_poll_t handle,
uv_os_sock_t  socket 
)

Definition at line 413 of file poll.c.

414  {
415  WSAPROTOCOL_INFOW protocol_info;
416  int len;
417  SOCKET peer_socket, base_socket;
418  DWORD bytes;
419  DWORD yes = 1;
420 
421  /* Set the socket to nonblocking mode */
422  if (ioctlsocket(socket, FIONBIO, &yes) == SOCKET_ERROR)
423  return uv_translate_sys_error(WSAGetLastError());
424 
425 /* Try to obtain a base handle for the socket. This increases this chances that
426  * we find an AFD handle and are able to use the fast poll mechanism. This will
427  * always fail on windows XP/2k3, since they don't support the. SIO_BASE_HANDLE
428  * ioctl. */
429 #ifndef NDEBUG
430  base_socket = INVALID_SOCKET;
431 #endif
432 
433  if (WSAIoctl(socket,
435  NULL,
436  0,
437  &base_socket,
438  sizeof base_socket,
439  &bytes,
440  NULL,
441  NULL) == 0) {
442  assert(base_socket != 0 && base_socket != INVALID_SOCKET);
443  socket = base_socket;
444  }
445 
446  uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL);
447  handle->socket = socket;
448  handle->events = 0;
449 
450  /* Obtain protocol information about the socket. */
451  len = sizeof protocol_info;
452  if (getsockopt(socket,
453  SOL_SOCKET,
454  SO_PROTOCOL_INFOW,
455  (char*) &protocol_info,
456  &len) != 0) {
457  return uv_translate_sys_error(WSAGetLastError());
458  }
459 
460  /* Get the peer socket that is needed to enable fast poll. If the returned
461  * value is NULL, the protocol is not implemented by MSAFD and we'll have to
462  * use slow mode. */
463  peer_socket = uv__fast_poll_get_peer_socket(loop, &protocol_info);
464 
465  if (peer_socket != INVALID_SOCKET) {
466  /* Initialize fast poll specific fields. */
467  handle->peer_socket = peer_socket;
468  } else {
469  /* Initialize slow poll specific fields. */
470  handle->flags |= UV_HANDLE_POLL_SLOW;
471  }
472 
473  /* Initialize 2 poll reqs. */
474  handle->submitted_events_1 = 0;
475  UV_REQ_INIT(&handle->poll_req_1, UV_POLL_REQ);
476  handle->poll_req_1.data = handle;
477 
478  handle->submitted_events_2 = 0;
479  UV_REQ_INIT(&handle->poll_req_2, UV_POLL_REQ);
480  handle->poll_req_2.data = handle;
481 
482  return 0;
483 }
size_t len
Definition: 6502dis.c:15
static ut8 bytes[32]
Definition: asm_arc.c:23
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
#define SOL_SOCKET
Definition: sftypes.h:427
#define FIONBIO
Definition: sftypes.h:736
#define UV_REQ_INIT(req, typ)
Definition: uv-common.h:322
#define uv__handle_init(loop_, h, type_)
Definition: uv-common.h:301
static SOCKET uv__fast_poll_get_peer_socket(uv_loop_t *loop, WSAPROTOCOL_INFOW *protocol_info)
Definition: poll.c:236
#define SIO_BASE_HANDLE
Definition: winsock.h:54

References assert(), bytes, DWORD, FIONBIO, handle, len, loop, NULL, SIO_BASE_HANDLE, socket, SOL_SOCKET, uv__fast_poll_get_peer_socket(), uv__handle_init, UV_HANDLE_POLL_SLOW, uv_poll_init(), UV_REQ_INIT, and uv_translate_sys_error().

Referenced by create_curl_context().

◆ uv_poll_start()

int uv_poll_start ( uv_poll_t handle,
int  events,
uv_poll_cb  cb 
)

Definition at line 516 of file poll.c.

516  {
517  return uv__poll_set(handle, events, cb);
518 }
static int uv__poll_set(uv_poll_t *handle, int events, uv_poll_cb cb)
Definition: poll.c:486

References assert(), cb, handle, poll_cb(), uv__handle_start, uv__io_start(), uv__is_closing, uv__poll_set(), uv__poll_stop(), UV__POLLPRI, UV__POLLRDHUP, UV_DISCONNECT, UV_PRIORITIZED, UV_READABLE, and UV_WRITABLE.

Referenced by handle_socket().

◆ uv_poll_stop()

int uv_poll_stop ( uv_poll_t handle)

Definition at line 521 of file poll.c.

521  {
522  return uv__poll_set(handle, 0, handle->poll_cb);
523 }

References assert(), handle, uv__is_closing, uv__poll_set(), and uv__poll_stop().

Referenced by handle_socket().

◆ 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().

Variable Documentation

◆ afd_poll_info_dummy_

AFD_POLL_INFO afd_poll_info_dummy_
static

Definition at line 49 of file poll.c.

Referenced by uv__get_afd_poll_info_dummy().

◆ overlapped_dummy_

OVERLAPPED overlapped_dummy_
static

Definition at line 46 of file poll.c.

Referenced by uv__get_overlapped_dummy(), and uv__init_overlapped_dummy().

◆ overlapped_dummy_init_guard_

uv_once_t overlapped_dummy_init_guard_ = UV_ONCE_INIT
static

Definition at line 47 of file poll.c.

Referenced by uv__get_overlapped_dummy().

◆ uv_msafd_provider_ids

const GUID uv_msafd_provider_ids[UV_MSAFD_PROVIDER_COUNT]
static
Initial value:
= {
{0xe70f1aa0, 0xab8b, 0x11cf,
{0x8c, 0xa3, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92}},
{0xf9eab0c0, 0x26d4, 0x11d0,
{0xbb, 0xbf, 0x00, 0xaa, 0x00, 0x6c, 0x34, 0xe4}},
{0x9fc48064, 0x7298, 0x43e4,
{0xb7, 0xbd, 0x18, 0x1f, 0x20, 0x89, 0x79, 0x2a}}
}

Definition at line 31 of file poll.c.

Referenced by uv__fast_poll_get_peer_socket().