|
Line 0
Link Here
|
|
|
1 |
--- src/unix/udp.c.orig 2020-04-15 16:31:21 UTC |
| 2 |
+++ src/unix/udp.c |
| 3 |
@@ -214,11 +214,14 @@ static int uv__udp_recvmmsg(uv_udp_t* handle, uv_buf_t |
| 4 |
else |
| 5 |
handle->recv_cb(handle, UV__ERR(errno), buf, NULL, 0); |
| 6 |
} else { |
| 7 |
- /* pass each chunk to the application */ |
| 8 |
- for (k = 0; k < (size_t) nread && handle->recv_cb != NULL; k++) { |
| 9 |
- flags = UV_UDP_MMSG_CHUNK; |
| 10 |
+ /* count to zero, so the buffer base comes last */ |
| 11 |
+ for (k = nread; k > 0 && handle->recv_cb != NULL;) { |
| 12 |
+ k--; |
| 13 |
+ flags = 0; |
| 14 |
if (msgs[k].msg_hdr.msg_flags & MSG_TRUNC) |
| 15 |
flags |= UV_UDP_PARTIAL; |
| 16 |
+ if (k != 0) |
| 17 |
+ flags |= UV_UDP_MMSG_CHUNK; |
| 18 |
|
| 19 |
chunk_buf = uv_buf_init(iov[k].iov_base, iov[k].iov_len); |
| 20 |
handle->recv_cb(handle, |
| 21 |
@@ -227,10 +230,6 @@ static int uv__udp_recvmmsg(uv_udp_t* handle, uv_buf_t |
| 22 |
msgs[k].msg_hdr.msg_name, |
| 23 |
flags); |
| 24 |
} |
| 25 |
- |
| 26 |
- /* one last callback so the original buffer is freed */ |
| 27 |
- if (handle->recv_cb != NULL) |
| 28 |
- handle->recv_cb(handle, 0, buf, NULL, 0); |
| 29 |
} |
| 30 |
return nread; |
| 31 |
} |