Lines Matching refs:handle
43 static void uv__udp_run_completed(uv_udp_t* handle);
45 static void uv__udp_recvmsg(uv_udp_t* handle);
46 static void uv__udp_sendmsg(uv_udp_t* handle);
47 static int uv__udp_maybe_deferred_bind(uv_udp_t* handle,
52 void uv__udp_close(uv_udp_t* handle) { in uv__udp_close() argument
53 uv__io_close(handle->loop, &handle->io_watcher); in uv__udp_close()
54 uv__handle_stop(handle); in uv__udp_close()
56 if (handle->io_watcher.fd != -1) { in uv__udp_close()
57 uv__close(handle->io_watcher.fd); in uv__udp_close()
58 handle->io_watcher.fd = -1; in uv__udp_close()
63 void uv__udp_finish_close(uv_udp_t* handle) { in uv__udp_finish_close() argument
67 assert(!uv__io_active(&handle->io_watcher, POLLIN | POLLOUT)); in uv__udp_finish_close()
68 assert(handle->io_watcher.fd == -1); in uv__udp_finish_close()
70 while (!uv__queue_empty(&handle->write_queue)) { in uv__udp_finish_close()
71 q = uv__queue_head(&handle->write_queue); in uv__udp_finish_close()
76 uv__queue_insert_tail(&handle->write_completed_queue, &req->queue); in uv__udp_finish_close()
79 uv__udp_run_completed(handle); in uv__udp_finish_close()
81 assert(handle->send_queue_size == 0); in uv__udp_finish_close()
82 assert(handle->send_queue_count == 0); in uv__udp_finish_close()
85 handle->recv_cb = NULL; in uv__udp_finish_close()
86 handle->alloc_cb = NULL; in uv__udp_finish_close()
91 static void uv__udp_run_completed(uv_udp_t* handle) { in uv__udp_run_completed() argument
95 assert(!(handle->flags & UV_HANDLE_UDP_PROCESSING)); in uv__udp_run_completed()
96 handle->flags |= UV_HANDLE_UDP_PROCESSING; in uv__udp_run_completed()
98 while (!uv__queue_empty(&handle->write_completed_queue)) { in uv__udp_run_completed()
99 q = uv__queue_head(&handle->write_completed_queue); in uv__udp_run_completed()
103 uv__req_unregister(handle->loop); in uv__udp_run_completed()
105 handle->send_queue_size -= uv__count_bufs(req->bufs, req->nbufs); in uv__udp_run_completed()
106 handle->send_queue_count--; in uv__udp_run_completed()
124 if (uv__queue_empty(&handle->write_queue)) { in uv__udp_run_completed()
126 uv__io_stop(handle->loop, &handle->io_watcher, POLLOUT); in uv__udp_run_completed()
127 if (!uv__io_active(&handle->io_watcher, POLLIN)) in uv__udp_run_completed()
128 uv__handle_stop(handle); in uv__udp_run_completed()
131 handle->flags &= ~UV_HANDLE_UDP_PROCESSING; in uv__udp_run_completed()
136 uv_udp_t* handle; in uv__udp_io() local
138 handle = container_of(w, uv_udp_t, io_watcher); in uv__udp_io()
139 assert(handle->type == UV_UDP); in uv__udp_io()
142 uv__udp_recvmsg(handle); in uv__udp_io()
144 if (revents & POLLOUT && !uv__is_closing(handle)) { in uv__udp_io()
145 uv__udp_sendmsg(handle); in uv__udp_io()
146 uv__udp_run_completed(handle); in uv__udp_io()
150 static int uv__udp_recvmmsg(uv_udp_t* handle, uv_buf_t* buf) { in uv__udp_recvmmsg() argument
181 nread = recvmsg_x(handle->io_watcher.fd, msgs, chunks, MSG_DONTWAIT); in uv__udp_recvmmsg()
185 nread = recvmmsg(handle->io_watcher.fd, msgs, chunks, 0, NULL); in uv__udp_recvmmsg()
191 handle->recv_cb(handle, 0, buf, NULL, 0); in uv__udp_recvmmsg()
193 handle->recv_cb(handle, UV__ERR(errno), buf, NULL, 0); in uv__udp_recvmmsg()
196 for (k = 0; k < (size_t) nread && handle->recv_cb != NULL; k++) { in uv__udp_recvmmsg()
202 handle->recv_cb(handle, in uv__udp_recvmmsg()
210 if (handle->recv_cb != NULL) in uv__udp_recvmmsg()
211 handle->recv_cb(handle, 0, buf, NULL, UV_UDP_MMSG_FREE); in uv__udp_recvmmsg()
219 static void uv__udp_recvmsg(uv_udp_t* handle) { in uv__udp_recvmsg() argument
227 assert(handle->recv_cb != NULL); in uv__udp_recvmsg()
228 assert(handle->alloc_cb != NULL); in uv__udp_recvmsg()
237 handle->alloc_cb((uv_handle_t*) handle, UV__UDP_DGRAM_MAXSIZE, &buf); in uv__udp_recvmsg()
239 handle->recv_cb(handle, UV_ENOBUFS, &buf, NULL, 0); in uv__udp_recvmsg()
244 if (uv_udp_using_recvmmsg(handle)) { in uv__udp_recvmsg()
245 nread = uv__udp_recvmmsg(handle, &buf); in uv__udp_recvmsg()
259 nread = recvmsg(handle->io_watcher.fd, &h, 0); in uv__udp_recvmsg()
265 handle->recv_cb(handle, 0, &buf, NULL, 0); in uv__udp_recvmsg()
267 handle->recv_cb(handle, UV__ERR(errno), &buf, NULL, 0); in uv__udp_recvmsg()
274 handle->recv_cb(handle, nread, &buf, (const struct sockaddr*) &peer, flags); in uv__udp_recvmsg()
281 && handle->io_watcher.fd != -1 in uv__udp_recvmsg()
282 && handle->recv_cb != NULL); in uv__udp_recvmsg()
285 static void uv__udp_sendmsg_one(uv_udp_t* handle, uv_udp_send_t* req) { in uv__udp_sendmsg_one() argument
312 size = sendmsg(handle->io_watcher.fd, &h, 0); in uv__udp_sendmsg_one()
327 uv__queue_insert_tail(&handle->write_completed_queue, &req->queue); in uv__udp_sendmsg_one()
328 uv__io_feed(handle->loop, &handle->io_watcher); in uv__udp_sendmsg_one()
330 if (uv__queue_empty(&handle->write_queue)) in uv__udp_sendmsg_one()
333 q = uv__queue_head(&handle->write_queue); in uv__udp_sendmsg_one()
339 static void uv__udp_sendmsg_many(uv_udp_t* handle) { in uv__udp_sendmsg_many() argument
349 for (pkts = 0, q = uv__queue_head(&handle->write_queue); in uv__udp_sendmsg_many()
350 pkts < ARRAY_SIZE(h) && q != &handle->write_queue; in uv__udp_sendmsg_many()
378 npkts = sendmsg_x(handle->io_watcher.fd, h, pkts, MSG_DONTWAIT); in uv__udp_sendmsg_many()
382 npkts = sendmmsg(handle->io_watcher.fd, h, pkts, 0); in uv__udp_sendmsg_many()
389 for (i = 0, q = uv__queue_head(&handle->write_queue); in uv__udp_sendmsg_many()
390 i < pkts && q != &handle->write_queue; in uv__udp_sendmsg_many()
391 ++i, q = uv__queue_head(&handle->write_queue)) { in uv__udp_sendmsg_many()
395 uv__queue_insert_tail(&handle->write_completed_queue, &req->queue); in uv__udp_sendmsg_many()
397 uv__io_feed(handle->loop, &handle->io_watcher); in uv__udp_sendmsg_many()
404 for (i = 0, q = uv__queue_head(&handle->write_queue); in uv__udp_sendmsg_many()
405 i < (size_t)npkts && q != &handle->write_queue; in uv__udp_sendmsg_many()
406 ++i, q = uv__queue_head(&handle->write_queue)) { in uv__udp_sendmsg_many()
416 uv__queue_insert_tail(&handle->write_completed_queue, &req->queue); in uv__udp_sendmsg_many()
420 if (!uv__queue_empty(&handle->write_queue)) in uv__udp_sendmsg_many()
423 uv__io_feed(handle->loop, &handle->io_watcher); in uv__udp_sendmsg_many()
427 static void uv__udp_sendmsg(uv_udp_t* handle) { in uv__udp_sendmsg() argument
431 if (uv__queue_empty(&handle->write_queue)) in uv__udp_sendmsg()
434 q = uv__queue_head(&handle->write_queue); in uv__udp_sendmsg()
442 if (req->nbufs != 1 || &handle->write_queue != uv__queue_next(&req->queue)) in uv__udp_sendmsg()
443 return uv__udp_sendmsg_many(handle); in uv__udp_sendmsg()
446 return uv__udp_sendmsg_one(handle, req); in uv__udp_sendmsg()
514 int uv__udp_bind(uv_udp_t* handle, in uv__udp_bind() argument
531 fd = handle->io_watcher.fd; in uv__udp_bind()
537 handle->io_watcher.fd = fd; in uv__udp_bind()
581 handle->flags |= UV_HANDLE_IPV6; in uv__udp_bind()
583 handle->flags |= UV_HANDLE_BOUND; in uv__udp_bind()
588 static int uv__udp_maybe_deferred_bind(uv_udp_t* handle, in uv__udp_maybe_deferred_bind() argument
594 if (handle->io_watcher.fd != -1) in uv__udp_maybe_deferred_bind()
621 return uv__udp_bind(handle, &taddr.addr, addrlen, flags); in uv__udp_maybe_deferred_bind()
625 int uv__udp_connect(uv_udp_t* handle, in uv__udp_connect() argument
630 err = uv__udp_maybe_deferred_bind(handle, addr->sa_family, 0); in uv__udp_connect()
636 err = connect(handle->io_watcher.fd, addr, addrlen); in uv__udp_connect()
642 handle->flags |= UV_HANDLE_UDP_CONNECTED; in uv__udp_connect()
678 int uv__udp_disconnect(uv_udp_t* handle) { in uv__udp_disconnect() argument
702 r = connect(handle->io_watcher.fd, (struct sockaddr*) NULL, 0); in uv__udp_disconnect()
704 r = connect(handle->io_watcher.fd, (struct sockaddr*) &addr, sizeof(addr)); in uv__udp_disconnect()
717 handle->flags &= ~UV_HANDLE_UDP_CONNECTED; in uv__udp_disconnect()
722 uv_udp_t* handle, in uv__udp_send() argument
734 err = uv__udp_maybe_deferred_bind(handle, addr->sa_family, 0); in uv__udp_send()
743 empty_queue = (handle->send_queue_count == 0); in uv__udp_send()
745 uv__req_init(handle->loop, req, UV_UDP_SEND); in uv__udp_send()
752 req->handle = handle; in uv__udp_send()
760 uv__req_unregister(handle->loop); in uv__udp_send()
765 handle->send_queue_size += uv__count_bufs(req->bufs, req->nbufs); in uv__udp_send()
766 handle->send_queue_count++; in uv__udp_send()
767 uv__queue_insert_tail(&handle->write_queue, &req->queue); in uv__udp_send()
768 uv__handle_start(handle); in uv__udp_send()
770 if (empty_queue && !(handle->flags & UV_HANDLE_UDP_PROCESSING)) { in uv__udp_send()
771 uv__udp_sendmsg(handle); in uv__udp_send()
777 if (!uv__queue_empty(&handle->write_queue)) in uv__udp_send()
778 uv__io_start(handle->loop, &handle->io_watcher, POLLOUT); in uv__udp_send()
780 uv__io_start(handle->loop, &handle->io_watcher, POLLOUT); in uv__udp_send()
787 int uv__udp_try_send(uv_udp_t* handle, in uv__udp_try_send() argument
799 if (handle->send_queue_count != 0) in uv__udp_try_send()
803 err = uv__udp_maybe_deferred_bind(handle, addr->sa_family, 0); in uv__udp_try_send()
807 assert(handle->flags & UV_HANDLE_UDP_CONNECTED); in uv__udp_try_send()
817 size = sendmsg(handle->io_watcher.fd, &h, 0); in uv__udp_try_send()
831 static int uv__udp_set_membership4(uv_udp_t* handle, in uv__udp_set_membership4() argument
862 if (setsockopt(handle->io_watcher.fd, in uv__udp_set_membership4()
878 static int uv__udp_set_membership6(uv_udp_t* handle, in uv__udp_set_membership6() argument
909 if (setsockopt(handle->io_watcher.fd, in uv__udp_set_membership6()
931 static int uv__udp_set_source_membership4(uv_udp_t* handle, in uv__udp_set_source_membership4() argument
940 err = uv__udp_maybe_deferred_bind(handle, AF_INET, UV_UDP_REUSEADDR); in uv__udp_set_source_membership4()
964 if (setsockopt(handle->io_watcher.fd, in uv__udp_set_source_membership4()
976 static int uv__udp_set_source_membership6(uv_udp_t* handle, in uv__udp_set_source_membership6() argument
986 err = uv__udp_maybe_deferred_bind(handle, AF_INET6, UV_UDP_REUSEADDR); in uv__udp_set_source_membership6()
1013 if (setsockopt(handle->io_watcher.fd, in uv__udp_set_source_membership6()
1027 uv_udp_t* handle, in uv__udp_init_ex() argument
1039 uv__handle_init(loop, (uv_handle_t*)handle, UV_UDP); in uv__udp_init_ex()
1040 handle->alloc_cb = NULL; in uv__udp_init_ex()
1041 handle->recv_cb = NULL; in uv__udp_init_ex()
1042 handle->send_queue_size = 0; in uv__udp_init_ex()
1043 handle->send_queue_count = 0; in uv__udp_init_ex()
1044 uv__io_init(&handle->io_watcher, uv__udp_io, fd); in uv__udp_init_ex()
1045 uv__queue_init(&handle->write_queue); in uv__udp_init_ex()
1046 uv__queue_init(&handle->write_completed_queue); in uv__udp_init_ex()
1052 int uv_udp_using_recvmmsg(const uv_udp_t* handle) { in uv_udp_using_recvmmsg() argument
1054 if (handle->flags & UV_HANDLE_UDP_RECVMMSG) in uv_udp_using_recvmmsg()
1061 int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) { in uv_udp_open() argument
1065 if (handle->io_watcher.fd != -1) in uv_udp_open()
1068 if (uv__fd_exists(handle->loop, sock)) in uv_udp_open()
1079 handle->io_watcher.fd = sock; in uv_udp_open()
1080 if (uv__udp_is_connected(handle)) in uv_udp_open()
1081 handle->flags |= UV_HANDLE_UDP_CONNECTED; in uv_udp_open()
1087 int uv_udp_set_membership(uv_udp_t* handle, in uv_udp_set_membership() argument
1096 err = uv__udp_maybe_deferred_bind(handle, AF_INET, UV_UDP_REUSEADDR); in uv_udp_set_membership()
1099 return uv__udp_set_membership4(handle, &addr4, interface_addr, membership); in uv_udp_set_membership()
1101 err = uv__udp_maybe_deferred_bind(handle, AF_INET6, UV_UDP_REUSEADDR); in uv_udp_set_membership()
1104 return uv__udp_set_membership6(handle, &addr6, interface_addr, membership); in uv_udp_set_membership()
1111 int uv_udp_set_source_membership(uv_udp_t* handle, in uv_udp_set_source_membership() argument
1134 return uv__udp_set_source_membership6(handle, in uv_udp_set_source_membership()
1144 return uv__udp_set_source_membership4(handle, in uv_udp_set_source_membership()
1155 static int uv__setsockopt(uv_udp_t* handle, in uv__setsockopt() argument
1162 if (handle->flags & UV_HANDLE_IPV6) in uv__setsockopt()
1163 r = setsockopt(handle->io_watcher.fd, in uv__setsockopt()
1169 r = setsockopt(handle->io_watcher.fd, in uv__setsockopt()
1180 static int uv__setsockopt_maybe_char(uv_udp_t* handle, in uv__setsockopt_maybe_char() argument
1195 return uv__setsockopt(handle, option4, option6, &arg, sizeof(arg)); in uv__setsockopt_maybe_char()
1199 int uv_udp_set_broadcast(uv_udp_t* handle, int on) { in uv_udp_set_broadcast() argument
1200 if (setsockopt(handle->io_watcher.fd, in uv_udp_set_broadcast()
1212 int uv_udp_set_ttl(uv_udp_t* handle, int ttl) { in uv_udp_set_ttl() argument
1217 if (!(handle->flags & UV_HANDLE_IPV6)) in uv_udp_set_ttl()
1230 return uv__setsockopt(handle, in uv_udp_set_ttl()
1239 return uv__setsockopt_maybe_char(handle, in uv_udp_set_ttl()
1249 int uv_udp_set_multicast_ttl(uv_udp_t* handle, int ttl) { in uv_udp_set_multicast_ttl() argument
1258 if (handle->flags & UV_HANDLE_IPV6) in uv_udp_set_multicast_ttl()
1259 return uv__setsockopt(handle, in uv_udp_set_multicast_ttl()
1267 return uv__setsockopt_maybe_char(handle, in uv_udp_set_multicast_ttl()
1274 int uv_udp_set_multicast_loop(uv_udp_t* handle, int on) { in uv_udp_set_multicast_loop() argument
1283 if (handle->flags & UV_HANDLE_IPV6) in uv_udp_set_multicast_loop()
1284 return uv__setsockopt(handle, in uv_udp_set_multicast_loop()
1292 return uv__setsockopt_maybe_char(handle, in uv_udp_set_multicast_loop()
1298 int uv_udp_set_multicast_interface(uv_udp_t* handle, const char* interface_addr) { in uv_udp_set_multicast_interface() argument
1308 if (handle->flags & UV_HANDLE_IPV6) { in uv_udp_set_multicast_interface()
1324 if (setsockopt(handle->io_watcher.fd, in uv_udp_set_multicast_interface()
1332 if (setsockopt(handle->io_watcher.fd, in uv_udp_set_multicast_interface()
1347 int uv_udp_getpeername(const uv_udp_t* handle, in uv_udp_getpeername() argument
1351 return uv__getsockpeername((const uv_handle_t*) handle, in uv_udp_getpeername()
1357 int uv_udp_getsockname(const uv_udp_t* handle, in uv_udp_getsockname() argument
1361 return uv__getsockpeername((const uv_handle_t*) handle, in uv_udp_getsockname()
1368 int uv__udp_recv_start(uv_udp_t* handle, in uv__udp_recv_start() argument
1376 if (uv__io_active(&handle->io_watcher, POLLIN)) in uv__udp_recv_start()
1379 err = uv__udp_maybe_deferred_bind(handle, AF_INET, 0); in uv__udp_recv_start()
1383 handle->alloc_cb = alloc_cb; in uv__udp_recv_start()
1384 handle->recv_cb = recv_cb; in uv__udp_recv_start()
1386 uv__io_start(handle->loop, &handle->io_watcher, POLLIN); in uv__udp_recv_start()
1387 uv__handle_start(handle); in uv__udp_recv_start()
1393 int uv__udp_recv_stop(uv_udp_t* handle) { in uv__udp_recv_stop() argument
1394 uv__io_stop(handle->loop, &handle->io_watcher, POLLIN); in uv__udp_recv_stop()
1396 if (!uv__io_active(&handle->io_watcher, POLLOUT)) in uv__udp_recv_stop()
1397 uv__handle_stop(handle); in uv__udp_recv_stop()
1399 handle->alloc_cb = NULL; in uv__udp_recv_stop()
1400 handle->recv_cb = NULL; in uv__udp_recv_stop()