--- a/llarp/ev/libuv.cpp.orig +++ b/llarp/ev/libuv.cpp @@ -18,6 +18,33 @@ #include #include +#ifdef __APPLE__ +// macOS has no sendmmsg(2), no struct mmsghdr, and no MSG_NOSIGNAL. Emulate +// the batched send with a sendmsg(2) loop (SIGPIPE is not a concern for +// unconnected UDP sendmsg, so MSG_NOSIGNAL can simply be neutralized). +#ifndef MSG_NOSIGNAL +#define MSG_NOSIGNAL 0 +#endif +struct mmsghdr +{ + struct msghdr msg_hdr; + unsigned int msg_len; +}; +static int +sendmmsg(int fd, struct mmsghdr* msgvec, unsigned int vlen, int flags) +{ + unsigned int sent = 0; + for (; sent < vlen; sent++) + { + const ssize_t ret = ::sendmsg(fd, &msgvec[sent].msg_hdr, flags); + if (ret < 0) + return sent ? static_cast(sent) : -1; + msgvec[sent].msg_len = static_cast(ret); + } + return static_cast(sent); +} +#endif // __APPLE__ + namespace llarp::uv { static auto logcat = log::Cat("libuv");