From c334176f3c6b60bf7eea42d3acc7096f5c42ab2f Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Wed, 18 Aug 2021 19:37:09 +0000 Subject: [PATCH] Fix recv problem --- w2u.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/w2u.c b/w2u.c index 29adf78..6da3f02 100644 --- a/w2u.c +++ b/w2u.c @@ -118,28 +118,30 @@ int main(int argc, char* argv[]) for (int i=0;i 0) { sendto(sender, buffer, nsize, 0, (const struct sockaddr*)(addrTargets + rrOffset), sizeof(struct sockaddr_in)); if (++rrOffset >= PORT_UR_SIZE) { rrOffset = 0; } } + + if (nsize < 0 && errno != EAGAIN) { + perror("recvfrom: "); + } } else if (events[i].data.fd == sender) { - int nsize = recvfrom(sender, buffer, sizeof(buffer), 0, NULL, NULL); - - if (nsize < 0) { - perror("recvfrom"); - } else { + int nsize; + while((nsize = recvfrom(sender, buffer, sizeof(buffer), 0, NULL, NULL)) > 0) { sendto(listener, buffer, nsize, 0, (const struct sockaddr*)&addrWg, sizeof(struct sockaddr_in)); } + + if (nsize < 0 && errno != EAGAIN) { + perror("recvfrom: "); + } } } }