Lines Matching defs:handle

27 #include "handle-inl.h"
75 static void uv__fast_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
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;
107 afd_poll_info->Handles[0].Handle = (HANDLE) handle->socket;
111 if (handle->events & UV_READABLE) {
115 if (handle->events & UV_DISCONNECT) {
119 if (handle->events & UV_WRITABLE) {
125 result = uv__msafd_poll((SOCKET) handle->peer_socket,
137 static void uv__fast_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
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;
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);
178 events &= handle->events & ~mask_events;
182 handle->events = 0;
183 if (uv__is_active(handle))
184 uv__handle_stop(handle);
188 handle->poll_cb(handle, 0, events);
192 if ((handle->events & ~(handle->submitted_events_1 |
193 handle->submitted_events_2)) != 0) {
194 uv__fast_poll_submit_poll_req(loop, handle);
195 } else if ((handle->flags & UV_HANDLE_CLOSING) &&
196 handle->submitted_events_1 == 0 &&
197 handle->submitted_events_2 == 0) {
198 uv__want_endgame(loop, (uv_handle_t*) handle);
269 uv_poll_t* handle = (uv_poll_t*) req->data;
275 assert(handle->type == UV_POLL);
278 if (handle->events & UV_READABLE) {
280 rfds.fd_array[0] = handle->socket;
285 if (handle->events & UV_WRITABLE) {
287 wfds.fd_array[0] = handle->socket;
289 efds.fd_array[0] = handle->socket;
303 SET_REQ_ERROR(&handle->poll_req_1, WSAGetLastError());
304 POST_COMPLETION_FOR_REQ(handle->loop, req);
313 assert(rfds.fd_array[0] == handle->socket);
319 assert(wfds.fd_array[0] == handle->socket);
323 assert(efds.fd_array[0] == handle->socket);
330 POST_COMPLETION_FOR_REQ(handle->loop, req);
336 static void uv__slow_poll_submit_poll_req(uv_loop_t* loop, uv_poll_t* handle) {
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;
366 static void uv__slow_poll_process_poll_req(uv_loop_t* loop, uv_poll_t* handle,
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;
384 if (handle->events != 0) {
386 handle->events = 0; /* Stop the watcher */
387 handle->poll_cb(handle, uv_translate_sys_error(err), 0);
391 int events = req->u.io.overlapped.InternalHigh & handle->events & ~mask_events;
393 handle->poll_cb(handle, 0, events);
397 if ((handle->events & ~(handle->submitted_events_1 |
398 handle->submitted_events_2)) != 0) {
399 uv__slow_poll_submit_poll_req(loop, handle);
400 } else if ((handle->flags & UV_HANDLE_CLOSING) &&
401 handle->submitted_events_1 == 0 &&
402 handle->submitted_events_2 == 0) {
403 uv__want_endgame(loop, (uv_handle_t*) handle);
408 int uv_poll_init(uv_loop_t* loop, uv_poll_t* handle, int fd) {
409 return uv_poll_init_socket(loop, handle, (SOCKET) uv__get_osfhandle(fd));
413 int uv_poll_init_socket(uv_loop_t* loop, uv_poll_t* handle,
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
446 uv__handle_init(loop, (uv_handle_t*) handle, UV_POLL);
447 handle->socket = socket;
448 handle->events = 0;
467 handle->peer_socket = peer_socket;
470 handle->flags |= UV_HANDLE_POLL_SLOW;
474 handle->submitted_events_1 = 0;
475 UV_REQ_INIT(&handle->poll_req_1, UV_POLL_REQ);
476 handle->poll_req_1.data = handle;
478 handle->submitted_events_2 = 0;
479 UV_REQ_INIT(&handle->poll_req_2, UV_POLL_REQ);
480 handle->poll_req_2.data = handle;
486 static int uv__poll_set(uv_poll_t* handle, int events, uv_poll_cb cb) {
489 assert(handle->type == UV_POLL);
490 assert(!(handle->flags & UV_HANDLE_CLOSING));
494 handle->events = events;
495 handle->poll_cb = cb;
497 if (handle->events == 0) {
498 uv__handle_stop(handle);
502 uv__handle_start(handle);
503 submitted_events = handle->submitted_events_1 | handle->submitted_events_2;
505 if (handle->events & ~submitted_events) {
506 if (handle->flags & UV_HANDLE_POLL_SLOW) {
507 uv__slow_poll_submit_poll_req(handle->loop, handle);
509 uv__fast_poll_submit_poll_req(handle->loop, handle);
517 int uv_poll_start(uv_poll_t* handle, int events, uv_poll_cb cb) {
518 return uv__poll_set(handle, events, cb);
522 int uv_poll_stop(uv_poll_t* handle) {
523 return uv__poll_set(handle, 0, handle->poll_cb);
527 void uv__process_poll_req(uv_loop_t* loop, uv_poll_t* handle, uv_req_t* req) {
528 if (!(handle->flags & UV_HANDLE_POLL_SLOW)) {
529 uv__fast_poll_process_poll_req(loop, handle, req);
531 uv__slow_poll_process_poll_req(loop, handle, req);
536 int uv__poll_close(uv_loop_t* loop, uv_poll_t* handle) {
541 handle->events = 0;
542 uv__handle_closing(handle);
544 if (handle->submitted_events_1 == 0 &&
545 handle->submitted_events_2 == 0) {
546 uv__want_endgame(loop, (uv_handle_t*) handle);
550 if (handle->flags & UV_HANDLE_POLL_SLOW)
558 afd_poll_info.Handles[0].Handle = (HANDLE) handle->socket;
562 result = uv__msafd_poll(handle->socket,
577 void uv__poll_endgame(uv_loop_t* loop, uv_poll_t* handle) {
578 assert(handle->flags & UV_HANDLE_CLOSING);
579 assert(!(handle->flags & UV_HANDLE_CLOSED));
581 assert(handle->submitted_events_1 == 0);
582 assert(handle->submitted_events_2 == 0);
584 uv__handle_close(handle);