|
|
@ -61,35 +61,9 @@ static void uv__udp_stop_watcher(uv_udp_t* handle, uv__io_t* w) { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void uv__udp_start_read_watcher(uv_udp_t* handle) { |
|
|
|
uv__udp_start_watcher(handle, |
|
|
|
&handle->read_watcher, |
|
|
|
uv__udp_recvmsg, |
|
|
|
UV__IO_READ); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void uv__udp_start_write_watcher(uv_udp_t* handle) { |
|
|
|
uv__udp_start_watcher(handle, |
|
|
|
&handle->write_watcher, |
|
|
|
uv__udp_sendmsg, |
|
|
|
UV__IO_WRITE); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void uv__udp_stop_read_watcher(uv_udp_t* handle) { |
|
|
|
uv__udp_stop_watcher(handle, &handle->read_watcher); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void uv__udp_stop_write_watcher(uv_udp_t* handle) { |
|
|
|
uv__udp_stop_watcher(handle, &handle->write_watcher); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uv__udp_close(uv_udp_t* handle) { |
|
|
|
uv__udp_stop_write_watcher(handle); |
|
|
|
uv__udp_stop_read_watcher(handle); |
|
|
|
uv__udp_stop_watcher(handle, &handle->write_watcher); |
|
|
|
uv__udp_stop_watcher(handle, &handle->read_watcher); |
|
|
|
close(handle->fd); |
|
|
|
handle->fd = -1; |
|
|
|
} |
|
|
@ -142,7 +116,8 @@ static void uv__udp_run_pending(uv_udp_t* handle) { |
|
|
|
|
|
|
|
memset(&h, 0, sizeof h); |
|
|
|
h.msg_name = &req->addr; |
|
|
|
h.msg_namelen = req->addrlen; |
|
|
|
h.msg_namelen = (req->addr.sin6_family == AF_INET6 ? |
|
|
|
sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in)); |
|
|
|
h.msg_iov = (struct iovec*)req->bufs; |
|
|
|
h.msg_iovlen = req->bufcnt; |
|
|
|
|
|
|
@ -224,7 +199,7 @@ static void uv__udp_recvmsg(uv_loop_t* loop, uv__io_t* w, int revents) { |
|
|
|
|
|
|
|
handle = container_of(w, uv_udp_t, read_watcher); |
|
|
|
assert(handle->type == UV_UDP); |
|
|
|
assert(revents & EV_READ); |
|
|
|
assert(revents & UV__IO_READ); |
|
|
|
|
|
|
|
assert(handle->recv_cb != NULL); |
|
|
|
assert(handle->alloc_cb != NULL); |
|
|
@ -281,7 +256,7 @@ static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents) { |
|
|
|
|
|
|
|
handle = container_of(w, uv_udp_t, write_watcher); |
|
|
|
assert(handle->type == UV_UDP); |
|
|
|
assert(revents & EV_WRITE); |
|
|
|
assert(revents & UV__IO_WRITE); |
|
|
|
|
|
|
|
assert(!ngx_queue_empty(&handle->write_queue) |
|
|
|
|| !ngx_queue_empty(&handle->write_completed_queue)); |
|
|
@ -298,7 +273,7 @@ static void uv__udp_sendmsg(uv_loop_t* loop, uv__io_t* w, int revents) { |
|
|
|
} |
|
|
|
else if (ngx_queue_empty(&handle->write_queue)) { |
|
|
|
/* Pending queue and completion queue empty, stop watcher. */ |
|
|
|
uv__udp_stop_write_watcher(handle); |
|
|
|
uv__udp_stop_watcher(handle, &handle->write_watcher); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -441,8 +416,8 @@ static int uv__udp_send(uv_udp_send_t* req, |
|
|
|
|
|
|
|
uv__req_init(handle->loop, req, UV_UDP_SEND); |
|
|
|
|
|
|
|
assert(addrlen <= sizeof(req->addr)); |
|
|
|
memcpy(&req->addr, addr, addrlen); |
|
|
|
req->addrlen = addrlen; |
|
|
|
req->send_cb = send_cb; |
|
|
|
req->handle = handle; |
|
|
|
req->bufcnt = bufcnt; |
|
|
@ -457,7 +432,11 @@ static int uv__udp_send(uv_udp_send_t* req, |
|
|
|
memcpy(req->bufs, bufs, bufcnt * sizeof(bufs[0])); |
|
|
|
|
|
|
|
ngx_queue_insert_tail(&handle->write_queue, &req->queue); |
|
|
|
uv__udp_start_write_watcher(handle); |
|
|
|
|
|
|
|
uv__udp_start_watcher(handle, |
|
|
|
&handle->write_watcher, |
|
|
|
uv__udp_sendmsg, |
|
|
|
UV__IO_WRITE); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
@ -657,14 +636,18 @@ int uv_udp_recv_start(uv_udp_t* handle, |
|
|
|
|
|
|
|
handle->alloc_cb = alloc_cb; |
|
|
|
handle->recv_cb = recv_cb; |
|
|
|
uv__udp_start_read_watcher(handle); |
|
|
|
|
|
|
|
uv__udp_start_watcher(handle, |
|
|
|
&handle->read_watcher, |
|
|
|
uv__udp_recvmsg, |
|
|
|
UV__IO_READ); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int uv_udp_recv_stop(uv_udp_t* handle) { |
|
|
|
uv__udp_stop_read_watcher(handle); |
|
|
|
uv__udp_stop_watcher(handle, &handle->read_watcher); |
|
|
|
handle->alloc_cb = NULL; |
|
|
|
handle->recv_cb = NULL; |
|
|
|
return 0; |
|
|
|