Lines Matching refs:handle
34 int uv_udp_getpeername(const uv_udp_t* handle, in uv_udp_getpeername() argument
38 return uv__getsockpeername((const uv_handle_t*) handle, in uv_udp_getpeername()
46 int uv_udp_getsockname(const uv_udp_t* handle, in uv_udp_getsockname() argument
50 return uv__getsockpeername((const uv_handle_t*) handle, in uv_udp_getsockname()
58 static int uv__udp_set_socket(uv_loop_t* loop, uv_udp_t* handle, SOCKET socket, in uv__udp_set_socket() argument
64 if (handle->socket != INVALID_SOCKET) in uv__udp_set_socket()
103 handle->flags |= UV_HANDLE_SYNC_BYPASS_IOCP; in uv__udp_set_socket()
104 handle->func_wsarecv = uv__wsarecv_workaround; in uv__udp_set_socket()
105 handle->func_wsarecvfrom = uv__wsarecvfrom_workaround; in uv__udp_set_socket()
111 handle->socket = socket; in uv__udp_set_socket()
114 handle->flags |= UV_HANDLE_IPV6; in uv__udp_set_socket()
116 assert(!(handle->flags & UV_HANDLE_IPV6)); in uv__udp_set_socket()
124 uv_udp_t* handle, in uv__udp_init_ex() argument
127 uv__handle_init(loop, (uv_handle_t*) handle, UV_UDP); in uv__udp_init_ex()
128 handle->socket = INVALID_SOCKET; in uv__udp_init_ex()
129 handle->reqs_pending = 0; in uv__udp_init_ex()
130 handle->activecnt = 0; in uv__udp_init_ex()
131 handle->func_wsarecv = WSARecv; in uv__udp_init_ex()
132 handle->func_wsarecvfrom = WSARecvFrom; in uv__udp_init_ex()
133 handle->send_queue_size = 0; in uv__udp_init_ex()
134 handle->send_queue_count = 0; in uv__udp_init_ex()
135 UV_REQ_INIT(&handle->recv_req, UV_UDP_RECV); in uv__udp_init_ex()
136 handle->recv_req.data = handle; in uv__udp_init_ex()
149 uv__queue_remove(&handle->handle_queue); in uv__udp_init_ex()
153 err = uv__udp_set_socket(handle->loop, handle, sock, domain); in uv__udp_init_ex()
156 uv__queue_remove(&handle->handle_queue); in uv__udp_init_ex()
165 void uv__udp_close(uv_loop_t* loop, uv_udp_t* handle) { in uv__udp_close() argument
166 uv_udp_recv_stop(handle); in uv__udp_close()
167 closesocket(handle->socket); in uv__udp_close()
168 handle->socket = INVALID_SOCKET; in uv__udp_close()
170 uv__handle_closing(handle); in uv__udp_close()
172 if (handle->reqs_pending == 0) { in uv__udp_close()
173 uv__want_endgame(loop, (uv_handle_t*) handle); in uv__udp_close()
178 void uv__udp_endgame(uv_loop_t* loop, uv_udp_t* handle) { in uv__udp_endgame() argument
179 if (handle->flags & UV_HANDLE_CLOSING && in uv__udp_endgame()
180 handle->reqs_pending == 0) { in uv__udp_endgame()
181 assert(!(handle->flags & UV_HANDLE_CLOSED)); in uv__udp_endgame()
182 uv__handle_close(handle); in uv__udp_endgame()
187 int uv_udp_using_recvmmsg(const uv_udp_t* handle) { in uv_udp_using_recvmmsg() argument
192 static int uv__udp_maybe_bind(uv_udp_t* handle, in uv__udp_maybe_bind() argument
200 if (handle->flags & UV_HANDLE_BOUND) in uv__udp_maybe_bind()
214 if (handle->socket == INVALID_SOCKET) { in uv__udp_maybe_bind()
220 err = uv__udp_set_socket(handle->loop, handle, sock, addr->sa_family); in uv__udp_maybe_bind()
230 if (setsockopt(handle->socket, in uv__udp_maybe_bind()
241 handle->flags |= UV_HANDLE_IPV6; in uv__udp_maybe_bind()
250 setsockopt(handle->socket, in uv__udp_maybe_bind()
257 r = bind(handle->socket, addr, addrlen); in uv__udp_maybe_bind()
262 handle->flags |= UV_HANDLE_BOUND; in uv__udp_maybe_bind()
268 static void uv__udp_queue_recv(uv_loop_t* loop, uv_udp_t* handle) { in uv__udp_queue_recv() argument
274 assert(handle->flags & UV_HANDLE_READING); in uv__udp_queue_recv()
275 assert(!(handle->flags & UV_HANDLE_READ_PENDING)); in uv__udp_queue_recv()
277 req = &handle->recv_req; in uv__udp_queue_recv()
280 handle->flags |= UV_HANDLE_ZERO_READ; in uv__udp_queue_recv()
286 result = handle->func_wsarecv(handle->socket, in uv__udp_queue_recv()
296 handle->flags |= UV_HANDLE_READ_PENDING; in uv__udp_queue_recv()
298 handle->reqs_pending++; in uv__udp_queue_recv()
302 handle->flags |= UV_HANDLE_READ_PENDING; in uv__udp_queue_recv()
303 handle->reqs_pending++; in uv__udp_queue_recv()
308 handle->reqs_pending++; in uv__udp_queue_recv()
313 int uv__udp_recv_start(uv_udp_t* handle, uv_alloc_cb alloc_cb, in uv__udp_recv_start() argument
315 uv_loop_t* loop = handle->loop; in uv__udp_recv_start()
318 if (handle->flags & UV_HANDLE_READING) { in uv__udp_recv_start()
322 err = uv__udp_maybe_bind(handle, in uv__udp_recv_start()
329 handle->flags |= UV_HANDLE_READING; in uv__udp_recv_start()
330 INCREASE_ACTIVE_COUNT(loop, handle); in uv__udp_recv_start()
332 handle->recv_cb = recv_cb; in uv__udp_recv_start()
333 handle->alloc_cb = alloc_cb; in uv__udp_recv_start()
337 if (!(handle->flags & UV_HANDLE_READ_PENDING)) in uv__udp_recv_start()
338 uv__udp_queue_recv(loop, handle); in uv__udp_recv_start()
344 int uv__udp_recv_stop(uv_udp_t* handle) { in uv__udp_recv_stop() argument
345 if (handle->flags & UV_HANDLE_READING) { in uv__udp_recv_stop()
346 handle->flags &= ~UV_HANDLE_READING; in uv__udp_recv_stop()
347 DECREASE_ACTIVE_COUNT(loop, handle); in uv__udp_recv_stop()
355 uv_udp_t* handle, in uv__send() argument
361 uv_loop_t* loop = handle->loop; in uv__send()
365 req->handle = handle; in uv__send()
369 result = WSASendTo(handle->socket, in uv__send()
382 handle->reqs_pending++; in uv__send()
383 handle->send_queue_size += req->u.io.queued_bytes; in uv__send()
384 handle->send_queue_count++; in uv__send()
385 REGISTER_HANDLE_REQ(loop, handle); in uv__send()
390 handle->reqs_pending++; in uv__send()
391 handle->send_queue_size += req->u.io.queued_bytes; in uv__send()
392 handle->send_queue_count++; in uv__send()
393 REGISTER_HANDLE_REQ(loop, handle); in uv__send()
403 void uv__process_udp_recv_req(uv_loop_t* loop, uv_udp_t* handle, in uv__process_udp_recv_req() argument
408 assert(handle->type == UV_UDP); in uv__process_udp_recv_req()
410 handle->flags &= ~UV_HANDLE_READ_PENDING; in uv__process_udp_recv_req()
422 if (!(handle->flags & UV_HANDLE_ZERO_READ)) { in uv__process_udp_recv_req()
428 if (handle->flags & UV_HANDLE_READING) { in uv__process_udp_recv_req()
429 uv_udp_recv_stop(handle); in uv__process_udp_recv_req()
430 buf = (handle->flags & UV_HANDLE_ZERO_READ) ? in uv__process_udp_recv_req()
431 uv_buf_init(NULL, 0) : handle->recv_buffer; in uv__process_udp_recv_req()
432 handle->recv_cb(handle, uv_translate_sys_error(err), &buf, NULL, 0); in uv__process_udp_recv_req()
438 if (!(handle->flags & UV_HANDLE_ZERO_READ)) { in uv__process_udp_recv_req()
441 handle->recv_cb(handle, in uv__process_udp_recv_req()
443 &handle->recv_buffer, in uv__process_udp_recv_req()
444 (const struct sockaddr*) &handle->recv_from, in uv__process_udp_recv_req()
446 } else if (handle->flags & UV_HANDLE_READING) { in uv__process_udp_recv_req()
459 handle->alloc_cb((uv_handle_t*) handle, UV__UDP_DGRAM_MAXSIZE, &buf); in uv__process_udp_recv_req()
461 handle->recv_cb(handle, UV_ENOBUFS, &buf, NULL, 0); in uv__process_udp_recv_req()
470 if (WSARecvFrom(handle->socket, in uv__process_udp_recv_req()
482 handle->recv_cb(handle, bytes, &buf, (const struct sockaddr*) &from, 0); in uv__process_udp_recv_req()
487 handle->recv_cb(handle, in uv__process_udp_recv_req()
494 handle->recv_cb(handle, 0, &buf, NULL, 0); in uv__process_udp_recv_req()
499 handle->recv_cb(handle, 0, &buf, NULL, 0); in uv__process_udp_recv_req()
502 uv_udp_recv_stop(handle); in uv__process_udp_recv_req()
503 handle->recv_cb(handle, uv_translate_sys_error(err), &buf, NULL, 0); in uv__process_udp_recv_req()
510 (handle->flags & UV_HANDLE_READING) && in uv__process_udp_recv_req()
511 !(handle->flags & UV_HANDLE_READ_PENDING)); in uv__process_udp_recv_req()
516 if ((handle->flags & UV_HANDLE_READING) && in uv__process_udp_recv_req()
517 !(handle->flags & UV_HANDLE_READ_PENDING)) { in uv__process_udp_recv_req()
518 uv__udp_queue_recv(loop, handle); in uv__process_udp_recv_req()
521 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_udp_recv_req()
525 void uv__process_udp_send_req(uv_loop_t* loop, uv_udp_t* handle, in uv__process_udp_send_req() argument
529 assert(handle->type == UV_UDP); in uv__process_udp_send_req()
531 assert(handle->send_queue_size >= req->u.io.queued_bytes); in uv__process_udp_send_req()
532 assert(handle->send_queue_count >= 1); in uv__process_udp_send_req()
533 handle->send_queue_size -= req->u.io.queued_bytes; in uv__process_udp_send_req()
534 handle->send_queue_count--; in uv__process_udp_send_req()
536 UNREGISTER_HANDLE_REQ(loop, handle); in uv__process_udp_send_req()
546 DECREASE_PENDING_REQ_COUNT(handle); in uv__process_udp_send_req()
550 static int uv__udp_set_membership4(uv_udp_t* handle, in uv__udp_set_membership4() argument
558 if (handle->flags & UV_HANDLE_IPV6) in uv__udp_set_membership4()
562 err = uv__udp_maybe_bind(handle, in uv__udp_set_membership4()
592 if (setsockopt(handle->socket, in uv__udp_set_membership4()
604 int uv__udp_set_membership6(uv_udp_t* handle, in uv__udp_set_membership6() argument
613 if ((handle->flags & UV_HANDLE_BOUND) && !(handle->flags & UV_HANDLE_IPV6)) in uv__udp_set_membership6()
616 err = uv__udp_maybe_bind(handle, in uv__udp_set_membership6()
647 if (setsockopt(handle->socket, in uv__udp_set_membership6()
659 static int uv__udp_set_source_membership4(uv_udp_t* handle, in uv__udp_set_source_membership4() argument
668 if (handle->flags & UV_HANDLE_IPV6) in uv__udp_set_source_membership4()
672 err = uv__udp_maybe_bind(handle, in uv__udp_set_source_membership4()
699 if (setsockopt(handle->socket, in uv__udp_set_source_membership4()
711 int uv__udp_set_source_membership6(uv_udp_t* handle, in uv__udp_set_source_membership6() argument
724 if ((handle->flags & UV_HANDLE_BOUND) && !(handle->flags & UV_HANDLE_IPV6)) in uv__udp_set_source_membership6()
727 err = uv__udp_maybe_bind(handle, in uv__udp_set_source_membership6()
756 if (setsockopt(handle->socket, in uv__udp_set_source_membership6()
768 int uv_udp_set_membership(uv_udp_t* handle, in uv_udp_set_membership() argument
776 return uv__udp_set_membership4(handle, &addr4, interface_addr, membership); in uv_udp_set_membership()
778 return uv__udp_set_membership6(handle, &addr6, interface_addr, membership); in uv_udp_set_membership()
784 int uv_udp_set_source_membership(uv_udp_t* handle, in uv_udp_set_source_membership() argument
810 return uv__udp_set_source_membership6(handle, in uv_udp_set_source_membership()
820 return uv__udp_set_source_membership4(handle, in uv_udp_set_source_membership()
828 int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr) { in uv_udp_set_multicast_interface() argument
838 if (handle->flags & UV_HANDLE_IPV6) { in uv_udp_set_multicast_interface()
853 if (handle->socket == INVALID_SOCKET) in uv_udp_set_multicast_interface()
857 if (setsockopt(handle->socket, in uv_udp_set_multicast_interface()
865 if (setsockopt(handle->socket, in uv_udp_set_multicast_interface()
881 int uv_udp_set_broadcast(uv_udp_t* handle, int value) { in uv_udp_set_broadcast() argument
884 if (handle->socket == INVALID_SOCKET) in uv_udp_set_broadcast()
887 if (setsockopt(handle->socket, in uv_udp_set_broadcast()
899 int uv__udp_is_bound(uv_udp_t* handle) { in uv__udp_is_bound() argument
904 if (uv_udp_getsockname(handle, (struct sockaddr*) &addr, &addrlen) != 0) in uv__udp_is_bound()
911 int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) { in uv_udp_open() argument
926 err = uv__udp_set_socket(handle->loop, in uv_udp_open()
927 handle, in uv_udp_open()
933 if (uv__udp_is_bound(handle)) in uv_udp_open()
934 handle->flags |= UV_HANDLE_BOUND; in uv_udp_open()
936 if (uv__udp_is_connected(handle)) in uv_udp_open()
937 handle->flags |= UV_HANDLE_UDP_CONNECTED; in uv_udp_open()
944 int uv_udp_set_##name(uv_udp_t* handle, int value) { \
951 if (handle->socket == INVALID_SOCKET) \
954 if (!(handle->flags & UV_HANDLE_IPV6)) { \
956 if (setsockopt(handle->socket, \
965 if (setsockopt(handle->socket, \
1002 int uv__udp_bind(uv_udp_t* handle, in SOCKOPT_SETTER()
1008 err = uv__udp_maybe_bind(handle, addr, addrlen, flags); in SOCKOPT_SETTER()
1016 int uv__udp_connect(uv_udp_t* handle, in uv__udp_connect() argument
1022 if (!(handle->flags & UV_HANDLE_BOUND)) { in uv__udp_connect()
1030 err = uv__udp_maybe_bind(handle, bind_addr, addrlen, 0); in uv__udp_connect()
1035 err = connect(handle->socket, addr, addrlen); in uv__udp_connect()
1039 handle->flags |= UV_HANDLE_UDP_CONNECTED; in uv__udp_connect()
1045 int uv__udp_disconnect(uv_udp_t* handle) { in uv__udp_disconnect() argument
1051 err = connect(handle->socket, (struct sockaddr*) &addr, sizeof(addr)); in uv__udp_disconnect()
1055 handle->flags &= ~UV_HANDLE_UDP_CONNECTED; in uv__udp_disconnect()
1064 uv_udp_t* handle, in uv__udp_send() argument
1073 if (!(handle->flags & UV_HANDLE_BOUND)) { in uv__udp_send()
1081 err = uv__udp_maybe_bind(handle, bind_addr, addrlen, 0); in uv__udp_send()
1086 err = uv__send(req, handle, bufs, nbufs, addr, addrlen, send_cb); in uv__udp_send()
1094 int uv__udp_try_send(uv_udp_t* handle, in uv__udp_try_send() argument
1114 if (handle->send_queue_count != 0) in uv__udp_try_send()
1117 if (!(handle->flags & UV_HANDLE_BOUND)) { in uv__udp_try_send()
1124 err = uv__udp_maybe_bind(handle, bind_addr, addrlen, 0); in uv__udp_try_send()
1129 err = WSASendTo(handle->socket, in uv__udp_try_send()