Said that, the fact that udp_recv_cb is called in the *reverse* order (so first received datagram is notified the last) makes me crazy.
On Thu, 12 Mar 2020 at 20:04, Iñaki Baz Castillo <[email protected]> wrote: > > > I just want to be sure that the buffer and nread given in > > uv_udp_recv_cb will just point to a **single** received UDP datagram > > (as always). I assume this is true, otherwise it would be a super > > breaking change since the application should do parsing to separate > > different messages received into two separate UDP datagrams. > > Ok, by looking at the code in depth it seems that, indeed, nothing > changes and, no matter recvmmsg is used, a recv_cb() is called for > each received datagram: > > In src/unix/udp.c: > > -------------------------------- > #if HAVE_MMSG > static int uv__udp_recvmmsg(uv_udp_t* handle, uv_buf_t* buf) { > struct sockaddr_in6 peers[UV__MMSG_MAXWIDTH]; > struct iovec iov[UV__MMSG_MAXWIDTH]; > struct uv__mmsghdr msgs[UV__MMSG_MAXWIDTH]; > ssize_t nread; > uv_buf_t chunk_buf; > size_t chunks; > int flags; > size_t k; > > /* prepare structures for recvmmsg */ > chunks = buf->len / UV__UDP_DGRAM_MAXSIZE; > if (chunks > ARRAY_SIZE(iov)) > chunks = ARRAY_SIZE(iov); > for (k = 0; k < chunks; ++k) { > iov[k].iov_base = buf->base + k * UV__UDP_DGRAM_MAXSIZE; > iov[k].iov_len = UV__UDP_DGRAM_MAXSIZE; > msgs[k].msg_hdr.msg_iov = iov + k; > msgs[k].msg_hdr.msg_iovlen = 1; > msgs[k].msg_hdr.msg_name = peers + k; > msgs[k].msg_hdr.msg_namelen = sizeof(peers[0]); > } > > do > nread = uv__recvmmsg(handle->io_watcher.fd, msgs, chunks, 0, NULL); > while (nread == -1 && errno == EINTR); > > if (nread < 1) { > if (nread == 0 || errno == EAGAIN || errno == EWOULDBLOCK) > handle->recv_cb(handle, 0, buf, NULL, 0); > else > handle->recv_cb(handle, UV__ERR(errno), buf, NULL, 0); > } else { > /* count to zero, so the buffer base comes last */ > for (k = nread; k > 0 && handle->recv_cb != NULL;) { > k--; > flags = 0; > if (msgs[k].msg_hdr.msg_flags & MSG_TRUNC) > flags |= UV_UDP_PARTIAL; > if (k != 0) > flags |= UV_UDP_MMSG_CHUNK; > > chunk_buf = uv_buf_init(iov[k].iov_base, iov[k].iov_len); > handle->recv_cb(handle, > msgs[k].msg_len, > &chunk_buf, > msgs[k].msg_hdr.msg_name, > flags); > } > } > return nread; > } > #endif > ----------------------- > > > -- > Iñaki Baz Castillo > <[email protected]> -- Iñaki Baz Castillo <[email protected]> -- You received this message because you are subscribed to the Google Groups "libuv" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/libuv/CALiegfkVQ9pyiV_1Rsi52z2actW%3DKu_ytRQerQX%2Bxpo2P%3DuphQ%40mail.gmail.com.
