diff --git a/daemon/io.c b/daemon/io.c index 5597c5a59138551a41d7085ceaba1553b6ad4c57..6f7e01187b50f75f3e5b33128e210aae55250350 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -70,13 +70,17 @@ void udp_recv(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, int udp_bind(struct endpoint *ep, struct sockaddr *addr) { uv_udp_t *handle = &ep->udp; - int ret = uv_udp_bind(handle, addr, 0); + unsigned flags = UV_UDP_REUSEADDR; + if (addr->sa_family == AF_INET6) { + flags |= UV_UDP_IPV6ONLY; + } + int ret = uv_udp_bind(handle, addr, flags); if (ret != 0) { return ret; } handle->data = NULL; - return uv_udp_recv_start(handle, &handle_getbuf, &udp_recv); + return io_start_read((uv_handle_t *)handle); } void udp_unbind(struct endpoint *ep) @@ -130,7 +134,11 @@ static void tcp_accept(uv_stream_t *master, int status) int tcp_bind(struct endpoint *ep, struct sockaddr *addr) { uv_tcp_t *handle = &ep->tcp; - int ret = uv_tcp_bind(handle, addr, 0); + unsigned flags = UV_UDP_REUSEADDR; + if (addr->sa_family == AF_INET6) { + flags |= UV_UDP_IPV6ONLY; + } + int ret = uv_tcp_bind(handle, addr, flags); if (ret != 0) { return ret; }