35 #define UV__UDP_DGRAM_MAXSIZE (64 * 1024)
37 #if defined(IPV6_JOIN_GROUP) && !defined(IPV6_ADD_MEMBERSHIP)
38 # define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
41 #if defined(IPV6_LEAVE_GROUP) && !defined(IPV6_DROP_MEMBERSHIP)
42 # define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
61 #define UV__MMSG_MAXWIDTH 20
66 static int uv__recvmmsg_avail;
67 static int uv__sendmmsg_avail;
70 static void uv__udp_mmsg_init(
void) {
77 if (ret == 0 || errno != ENOSYS) {
78 uv__sendmmsg_avail = 1;
79 uv__recvmmsg_avail = 1;
82 if (ret == 0 || errno != ENOSYS)
83 uv__recvmmsg_avail = 1;
94 if (
handle->io_watcher.fd != -1) {
96 handle->io_watcher.fd = -1;
113 req->status = UV_ECANCELED;
144 handle->send_queue_count--;
146 if (
req->bufs !=
req->bufsml)
156 if (
req->status >= 0)
179 if (revents & POLLIN)
182 if (revents & POLLOUT) {
191 struct iovec iov[UV__MMSG_MAXWIDTH];
192 struct uv__mmsghdr msgs[UV__MMSG_MAXWIDTH];
203 for (
k = 0;
k < chunks; ++
k) {
206 msgs[
k].msg_hdr.msg_iov =
iov +
k;
207 msgs[
k].msg_hdr.msg_iovlen = 1;
208 msgs[
k].msg_hdr.msg_name = peers +
k;
209 msgs[
k].msg_hdr.msg_namelen =
sizeof(peers[0]);
210 msgs[
k].msg_hdr.msg_control =
NULL;
211 msgs[
k].msg_hdr.msg_controllen = 0;
212 msgs[
k].msg_hdr.msg_flags = 0;
217 while (nread == -1 && errno ==
EINTR);
220 if (nread == 0 || errno ==
EAGAIN || errno == EWOULDBLOCK)
228 if (msgs[
k].msg_hdr.msg_flags & MSG_TRUNC)
235 msgs[
k].msg_hdr.msg_name,
248 struct sockaddr_storage peer;
282 memset(&peer, 0,
sizeof(peer));
284 h.msg_namelen =
sizeof(peer);
285 h.msg_iov = (
void*) &
buf;
289 nread = recvmsg(
handle->io_watcher.fd, &
h, 0);
291 while (nread == -1 && errno ==
EINTR);
294 if (errno ==
EAGAIN || errno == EWOULDBLOCK)
301 if (
h.msg_flags & MSG_TRUNC)
311 &&
handle->io_watcher.fd != -1
318 struct uv__mmsghdr
h[UV__MMSG_MAXWIDTH];
319 struct uv__mmsghdr *
p;
330 pkts < UV__MMSG_MAXWIDTH && q != &handle->write_queue;
339 p->msg_hdr.msg_name =
NULL;
340 p->msg_hdr.msg_namelen = 0;
342 p->msg_hdr.msg_name = &
req->addr;
350 assert(0 &&
"unsupported address family");
354 h[pkts].msg_hdr.msg_iov = (
struct iovec*)
req->bufs;
355 h[pkts].msg_hdr.msg_iovlen =
req->nbufs;
360 while (npkts == -1 && errno ==
EINTR);
363 if (errno ==
EAGAIN || errno == EWOULDBLOCK || errno ==
ENOBUFS)
366 i < pkts && q != &handle->write_queue;
381 i < pkts && q != &handle->write_queue;
387 req->status =
req->bufs[0].len;
400 goto write_queue_drain;
414 if (uv__sendmmsg_avail) {
432 h.msg_name = &
req->addr;
440 assert(0 &&
"unsupported address family");
445 h.msg_iovlen =
req->nbufs;
452 if (errno ==
EAGAIN || errno == EWOULDBLOCK || errno ==
ENOBUFS)
484 #if defined(SO_REUSEPORT) && defined(__MVS__)
486 unsigned int sockfd_len =
sizeof(
sockfd);
493 if (setsockopt(
fd,
SOL_SOCKET, SO_REUSEPORT, &yes,
sizeof(yes)))
496 #elif defined(SO_REUSEPORT) && !defined(__linux__)
497 if (setsockopt(
fd,
SOL_SOCKET, SO_REUSEPORT, &yes,
sizeof(yes)))
511 unsigned int flags) {
542 if (setsockopt(
fd, IPPROTO_IPV6,
IPV6_V6ONLY, &yes,
sizeof yes) == -1) {
571 unsigned int flags) {
575 if (
handle->io_watcher.fd != -1)
584 addr->sin_addr.s_addr = INADDR_ANY;
598 assert(0 &&
"unsupported address family");
618 }
while (
err == -1 && errno ==
EINTR);
640 }
while (
r == -1 && errno ==
EINTR);
672 empty_queue = (
handle->send_queue_count == 0);
680 req->send_cb = send_cb;
695 handle->send_queue_count++;
728 if (
handle->send_queue_count != 0)
743 h.msg_iovlen = nbufs;
750 if (errno ==
EAGAIN || errno == EWOULDBLOCK || errno ==
ENOBUFS)
762 const char* interface_addr,
768 memset(&mreq, 0,
sizeof mreq);
770 if (interface_addr) {
775 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
780 switch (membership) {
782 optname = IP_ADD_MEMBERSHIP;
785 optname = IP_DROP_MEMBERSHIP;
791 if (setsockopt(
handle->io_watcher.fd,
809 const char* interface_addr,
812 struct ipv6_mreq mreq;
815 memset(&mreq, 0,
sizeof mreq);
817 if (interface_addr) {
822 mreq.ipv6mr_interface = 0;
825 mreq.ipv6mr_multiaddr = multicast_addr->
sin6_addr;
827 switch (membership) {
829 optname = IPV6_ADD_MEMBERSHIP;
832 optname = IPV6_DROP_MEMBERSHIP;
838 if (setsockopt(
handle->io_watcher.fd,
854 #if !defined(__OpenBSD__) && \
855 !defined(__NetBSD__) && \
856 !defined(__ANDROID__) && \
857 !defined(__DragonFly__) & \
861 const char* interface_addr,
864 struct ip_mreq_source mreq;
872 memset(&mreq, 0,
sizeof(mreq));
874 if (interface_addr !=
NULL) {
879 mreq.imr_interface.s_addr = htonl(INADDR_ANY);
886 optname = IP_ADD_SOURCE_MEMBERSHIP;
888 optname = IP_DROP_SOURCE_MEMBERSHIP;
892 if (setsockopt(
handle->io_watcher.fd,
906 const char* interface_addr,
909 struct group_source_req mreq;
918 memset(&mreq, 0,
sizeof(mreq));
920 if (interface_addr !=
NULL) {
926 mreq.gsr_interface = 0;
929 STATIC_ASSERT(
sizeof(mreq.gsr_group) >=
sizeof(*multicast_addr));
930 STATIC_ASSERT(
sizeof(mreq.gsr_source) >=
sizeof(*source_addr));
931 memcpy(&mreq.gsr_group, multicast_addr,
sizeof(*multicast_addr));
932 memcpy(&mreq.gsr_source, source_addr,
sizeof(*source_addr));
941 if (setsockopt(
handle->io_watcher.fd,
970 handle->send_queue_size = 0;
971 handle->send_queue_count = 0;
984 return uv__recvmmsg_avail;
995 if (
handle->io_watcher.fd != -1)
1009 handle->io_watcher.fd = sock;
1018 const char* multicast_addr,
1019 const char* interface_addr,
1025 if (
uv_ip4_addr(multicast_addr, 0, &addr4) == 0) {
1030 }
else if (
uv_ip6_addr(multicast_addr, 0, &addr6) == 0) {
1042 const char* multicast_addr,
1043 const char* interface_addr,
1044 const char* source_addr,
1046 #if !defined(__OpenBSD__) && \
1047 !defined(__NetBSD__) && \
1048 !defined(__ANDROID__) && \
1049 !defined(__DragonFly__) && \
1092 r = setsockopt(
handle->io_watcher.fd,
1098 r = setsockopt(
handle->io_watcher.fd,
1113 #if defined(__sun) || defined(_AIX) || defined(__MVS__)
1115 #elif defined(__OpenBSD__)
1121 if (val < 0 || val > 255)
1129 if (setsockopt(
handle->io_watcher.fd,
1142 if (ttl < 1 || ttl > 255)
1145 #if defined(__MVS__)
1156 #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1157 defined(__MVS__) || defined(__QNX__)
1185 #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1186 defined(__MVS__) || defined(__QNX__)
1190 IPV6_MULTICAST_HOPS,
1198 IPV6_MULTICAST_HOPS,
1210 #if defined(__sun) || defined(_AIX) || defined(__OpenBSD__) || \
1211 defined(__MVS__) || defined(__QNX__)
1215 IPV6_MULTICAST_LOOP,
1223 IPV6_MULTICAST_LOOP,
1228 struct sockaddr_storage addr_st;
1235 if (!interface_addr) {
1236 memset(&addr_st, 0,
sizeof addr_st);
1244 }
else if (
uv_ip4_addr(interface_addr, 0, addr4) == 0) {
1246 }
else if (
uv_ip6_addr(interface_addr, 0, addr6) == 0) {
1252 if (addr_st.ss_family ==
AF_INET) {
1253 if (setsockopt(
handle->io_watcher.fd,
1260 }
else if (addr_st.ss_family ==
AF_INET6) {
1261 if (setsockopt(
handle->io_watcher.fd,
1269 assert(0 &&
"unexpected address family");
1302 if (alloc_cb ==
NULL || recv_cb ==
NULL)
1312 handle->alloc_cb = alloc_cb;
1313 handle->recv_cb = recv_cb;
static mcore_handle handle
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec req
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd domain
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
int uv__sendmmsg(int fd, struct uv__mmsghdr *mmsg, unsigned int vlen)
int uv__recvmmsg(int fd, struct uv__mmsghdr *mmsg, unsigned int vlen)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset void static length char static len const struct iovec static count unsigned long static filedes static sched_yield static flags static oldfd static pause unsigned static seconds static protocol struct sockaddr addrlen
assert(limit<=UINT32_MAX/2)
#define QUEUE_DATA(ptr, type, field)
#define QUEUE_INSERT_TAIL(h, q)
#define container_of(ptr, type, member)
static struct sockaddr static addrlen static backlog const void static flags void flags
static const struct in6_addr in6addr_any
struct in6_addr sin6_addr
void uv__io_stop(uv_loop_t *loop, uv__io_t *w, unsigned int events)
void uv__io_start(uv_loop_t *loop, uv__io_t *w, unsigned int events)
int uv__fd_exists(uv_loop_t *loop, int fd)
void uv__io_close(uv_loop_t *loop, uv__io_t *w)
int uv__getsockpeername(const uv_handle_t *handle, uv__peersockfunc func, struct sockaddr *name, int *namelen)
int uv__io_active(const uv__io_t *w, unsigned int events)
int uv__socket(int domain, int type, int protocol)
void uv__io_init(uv__io_t *w, uv__io_cb cb, int fd)
void uv__io_feed(uv_loop_t *loop, uv__io_t *w)
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
int uv_udp_set_source_membership(uv_udp_t *handle, const char *multicast_addr, const char *interface_addr, const char *source_addr, uv_membership membership)
static void uv__udp_sendmsg(uv_udp_t *handle)
void uv__udp_close(uv_udp_t *handle)
int uv__udp_init_ex(uv_loop_t *loop, uv_udp_t *handle, unsigned flags, int domain)
int uv__udp_send(uv_udp_send_t *req, uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr, unsigned int addrlen, uv_udp_send_cb send_cb)
static int uv__setsockopt(uv_udp_t *handle, int option4, int option6, const void *val, socklen_t size)
int uv_udp_set_ttl(uv_udp_t *handle, int ttl)
static int uv__udp_set_membership4(uv_udp_t *handle, const struct sockaddr_in *multicast_addr, const char *interface_addr, uv_membership membership)
#define UV__UDP_DGRAM_MAXSIZE
int uv_udp_set_broadcast(uv_udp_t *handle, int on)
int uv__udp_recv_start(uv_udp_t *handle, uv_alloc_cb alloc_cb, uv_udp_recv_cb recv_cb)
int uv__udp_disconnect(uv_udp_t *handle)
int uv__udp_connect(uv_udp_t *handle, const struct sockaddr *addr, unsigned int addrlen)
static void uv__udp_recvmsg(uv_udp_t *handle)
int uv_udp_using_recvmmsg(const uv_udp_t *handle)
int uv_udp_open(uv_udp_t *handle, uv_os_sock_t sock)
static int uv__set_reuse(int fd)
int uv__udp_recv_stop(uv_udp_t *handle)
static int uv__setsockopt_maybe_char(uv_udp_t *handle, int option4, int option6, int val)
int uv_udp_set_multicast_interface(uv_udp_t *handle, const char *interface_addr)
int uv__udp_try_send(uv_udp_t *handle, const uv_buf_t bufs[], unsigned int nbufs, const struct sockaddr *addr, unsigned int addrlen)
static void uv__udp_io(uv_loop_t *loop, uv__io_t *w, unsigned int revents)
static int uv__udp_set_source_membership6(uv_udp_t *handle, const struct sockaddr_in6 *multicast_addr, const char *interface_addr, const struct sockaddr_in6 *source_addr, uv_membership membership)
void uv__udp_finish_close(uv_udp_t *handle)
int uv_udp_set_multicast_loop(uv_udp_t *handle, int on)
static int uv__udp_set_source_membership4(uv_udp_t *handle, const struct sockaddr_in *multicast_addr, const char *interface_addr, const struct sockaddr_in *source_addr, uv_membership membership)
static int uv__udp_maybe_deferred_bind(uv_udp_t *handle, int domain, unsigned int flags)
static int uv__udp_set_membership6(uv_udp_t *handle, const struct sockaddr_in6 *multicast_addr, const char *interface_addr, uv_membership membership)
int uv_udp_getpeername(const uv_udp_t *handle, struct sockaddr *name, int *namelen)
int uv__udp_bind(uv_udp_t *handle, const struct sockaddr *addr, unsigned int addrlen, unsigned int flags)
static void uv__udp_run_completed(uv_udp_t *handle)
int uv_udp_set_multicast_ttl(uv_udp_t *handle, int ttl)
int uv_udp_getsockname(const uv_udp_t *handle, struct sockaddr *name, int *namelen)
int uv_udp_set_membership(uv_udp_t *handle, const char *multicast_addr, const char *interface_addr, uv_membership membership)
int uv__udp_is_connected(uv_udp_t *handle)
size_t uv__count_bufs(const uv_buf_t bufs[], unsigned int nbufs)
void * uv__malloc(size_t size)
@ UV_HANDLE_UDP_PROCESSING
@ UV_HANDLE_UDP_CONNECTED
#define uv__handle_init(loop_, h, type_)
#define STATIC_ASSERT(expr)
#define uv__handle_stop(h)
#define uv__req_init(loop, req, typ)
#define uv__req_unregister(loop, req)
#define uv__handle_start(h)
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
UV_EXTERN int uv_ip6_addr(const char *ip, int port, struct sockaddr_in6 *addr)
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
void(* uv_udp_recv_cb)(uv_udp_t *handle, ssize_t nread, const uv_buf_t *buf, const struct sockaddr *addr, unsigned flags)
void(* uv_udp_send_cb)(uv_udp_send_t *req, int status)
void(* uv_alloc_cb)(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
UV_EXTERN int uv_inet_pton(int af, const char *src, void *dst)
#define MCAST_LEAVE_SOURCE_GROUP
#define MCAST_JOIN_SOURCE_GROUP
static const z80_opcode fd[]