Lines Matching defs:handle

27 #include "handle-inl.h"
77 static void uv__fast_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
83 if (handle->submitted_events_1 == 0) {
84 req = &handle->poll_req_1;
85 afd_poll_info = &handle->afd_poll_info_1;
86 handle->submitted_events_1 = handle->events;
87 handle->mask_events_1 = 0;
88 handle->mask_events_2 = handle->events;
89 } else if (handle->submitted_events_2 == 0) {
90 req = &handle->poll_req_2;
91 afd_poll_info = &handle->afd_poll_info_2;
92 handle->submitted_events_2 = handle->events;
93 handle->mask_events_1 = handle->events;
94 handle->mask_events_2 = 0;
109 afd_poll_info->Handles[0].Handle = (HANDLE) handle->socket;
113 if (handle->events & UV_READABLE) {
117 if (handle->events & UV_DISCONNECT) {
121 if (handle->events & UV_WRITABLE) {
127 result = uv__msafd_poll((SOCKET) handle->peer_socket,
139 static void uv__fast_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
144 if (req == &handle->poll_req_1) {
145 afd_poll_info = &handle->afd_poll_info_1;
146 handle->submitted_events_1 = 0;
147 mask_events = handle->mask_events_1;
148 } else if (req == &handle->poll_req_2) {
149 afd_poll_info = &handle->afd_poll_info_2;
150 handle->submitted_events_2 = 0;
151 mask_events = handle->mask_events_2;
160 if (error != WSAEINTR && handle->events != 0) {
161 handle->events = 0; /* Stop the watcher */
162 handle->poll_cb(handle, uv_translate_sys_error(error), 0);
180 events &= handle->events & ~mask_events;
184 handle->events = 0;
185 if (uv__is_active(handle))
186 uv__handle_stop(handle);
190 handle->poll_cb(handle, 0, events);
194 if ((handle->events & ~(handle->submitted_events_1 |
195 handle->submitted_events_2)) != 0) {
196 uv__fast_poll_submit_poll_req(loop, handle);
197 } else if ((handle->flags & UV_HANDLE_CLOSING) &&
198 handle->submitted_events_1 == 0 &&
199 handle->submitted_events_2 == 0) {
200 uv__want_endgame(loop, (uv_handle_t*) handle);
271 uv_poll_t* handle = (uv_poll_t*) req->data;
277 assert(handle->type == UV_POLL);
280 if (handle->events & UV_READABLE) {
282 rfds.fd_array[0] = handle->socket;
287 if (handle->events & UV_WRITABLE) {
289 wfds.fd_array[0] = handle->socket;
291 efds.fd_array[0] = handle->socket;
305 SET_REQ_ERROR(&handle->poll_req_1, WSAGetLastError());
306 POST_COMPLETION_FOR_REQ(handle->loop, req);
315 assert(rfds.fd_array[0] == handle->socket);
321 assert(wfds.fd_array[0] == handle->socket);
325 assert(efds.fd_array[0] == handle->socket);
332 POST_COMPLETION_FOR_REQ(handle->loop, req);
338 static void uv__slow_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
342 if (handle->submitted_events_1 == 0) {
343 req = &handle->poll_req_1;
344 handle->submitted_events_1 = handle->events;
345 handle->mask_events_1 = 0;
346 handle->mask_events_2 = handle->events;
347 } else if (handle->submitted_events_2 == 0) {
348 req = &handle->poll_req_2;
349 handle->submitted_events_2 = handle->events;
350 handle->mask_events_1 = handle->events;
351 handle->mask_events_2 = 0;
368 static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
373 if (req == &handle->poll_req_1) {
374 handle->submitted_events_1 = 0;
375 mask_events = handle->mask_events_1;
376 } else if (req == &handle->poll_req_2) {
377 handle->submitted_events_2 = 0;
378 mask_events = handle->mask_events_2;
386 if (handle->events != 0) {
388 handle->events = 0; /* Stop the watcher */
389 handle->poll_cb(handle, uv_translate_sys_error(err), 0);
393 int events = req->u.io.overlapped.InternalHigh & handle->events & ~mask_events;
395 handle->poll_cb(handle, 0, events);
399 if ((handle->events & ~(handle->submitted_events_1 |
400 handle->submitted_events_2)) != 0) {
401 uv__slow_poll_submit_poll_req(loop, handle);
402 } else if ((handle->flags & UV_HANDLE_CLOSING) &&
403 handle->submitted_events_1 == 0 &&
404 handle->submitted_events_2 == 0) {
405 uv__want_endgame(loop, (uv_handle_t*) handle);
410 int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) {
411 return uv_poll_init_socket(loop, handle, (SOCKET) uv__get_osfhandle(fd));
415 int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
427 /* Try to obtain a base handle for the socket. This increases this chances that
428 * we find an AFD handle and are able to use the fast poll mechanism.
447 uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL);
448 handle->socket = socket;
449 handle->events = 0;
468 handle->peer_socket = peer_socket;
471 handle->flags |= UV_HANDLE_POLL_SLOW;
475 handle->submitted_events_1 = 0;
476 UV_REQ_INIT(&handle->poll_req_1, UV_POLL_REQ);
477 handle->poll_req_1.data = handle;
479 handle->submitted_events_2 = 0;
480 UV_REQ_INIT(&handle->poll_req_2, UV_POLL_REQ);
481 handle->poll_req_2.data = handle;
487 static int uv__poll_set(uv_poll_t* handle, int events, uv_poll_cb cb) {
490 assert(handle->type == UV_POLL);
491 assert(!(handle->flags & UV_HANDLE_CLOSING));
495 handle->events = events;
496 handle->poll_cb = cb;
498 if (handle->events == 0) {
499 uv__handle_stop(handle);
503 uv__handle_start(handle);
504 submitted_events = handle->submitted_events_1 | handle->submitted_events_2;
506 if (handle->events & ~submitted_events) {
507 if (handle->flags & UV_HANDLE_POLL_SLOW) {
508 uv__slow_poll_submit_poll_req(handle->loop, handle);
510 uv__fast_poll_submit_poll_req(handle->loop, handle);
518 int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb) {
519 return uv__poll_set(handle, events, cb);
523 int uv_poll_stop(uv_poll_t* handle) {
524 return uv__poll_set(handle, 0, handle->poll_cb);
528 void uv__process_poll_req(uv_loop_t* loop, uv_poll_t* handle, uv_req_t* req) {
529 if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
530 uv__fast_poll_process_poll_req(loop, handle, req);
532 uv__slow_poll_process_poll_req(loop, handle, req);
537 int uv__poll_close(uv_loop_t* loop, uv_poll_t* handle) {
542 handle->events = 0;
543 uv__handle_closing(handle);
545 if (handle->submitted_events_1 == 0 &&
546 handle->submitted_events_2 == 0) {
547 uv__want_endgame(loop, (uv_handle_t*) handle);
551 if (handle->flags & UV_HANDLE_POLL_SLOW)
559 afd_poll_info.Handles[0].Handle = (HANDLE) handle->socket;
563 result = uv__msafd_poll(handle->socket,
578 void uv__poll_endgame(uv_loop_t* loop, uv_poll_t* handle) {
579 assert(handle->flags & UV_HANDLE_CLOSING);
580 assert(!(handle->flags & UV_HANDLE_CLOSED));
582 assert(handle->submitted_events_1 == 0);
583 assert(handle->submitted_events_2 == 0);
585 uv__handle_close(handle);