Fix recv problem

This commit is contained in:
Kirigaya Kazuto 2021-08-18 19:37:09 +00:00
parent 6c46cab599
commit c334176f3c

22
w2u.c
View File

@ -120,26 +120,28 @@ int main(int argc, char* argv[])
{ {
if (events[i].data.fd == listener) if (events[i].data.fd == listener)
{ {
int nsize = recvfrom(listener, buffer, sizeof(buffer), 0, NULL, NULL); int nsize;
while((nsize = recvfrom(listener, buffer, sizeof(buffer), 0, NULL, NULL)) > 0) {
if (nsize < 0) {
perror("recvfrom");
} else {
sendto(sender, buffer, nsize, 0, (const struct sockaddr*)(addrTargets + rrOffset), sizeof(struct sockaddr_in)); sendto(sender, buffer, nsize, 0, (const struct sockaddr*)(addrTargets + rrOffset), sizeof(struct sockaddr_in));
if (++rrOffset >= PORT_UR_SIZE) { if (++rrOffset >= PORT_UR_SIZE) {
rrOffset = 0; rrOffset = 0;
} }
} }
if (nsize < 0 && errno != EAGAIN) {
perror("recvfrom: ");
}
} }
else if (events[i].data.fd == sender) else if (events[i].data.fd == sender)
{ {
int nsize = recvfrom(sender, buffer, sizeof(buffer), 0, NULL, NULL); int nsize;
while((nsize = recvfrom(sender, buffer, sizeof(buffer), 0, NULL, NULL)) > 0) {
if (nsize < 0) {
perror("recvfrom");
} else {
sendto(listener, buffer, nsize, 0, (const struct sockaddr*)&addrWg, sizeof(struct sockaddr_in)); sendto(listener, buffer, nsize, 0, (const struct sockaddr*)&addrWg, sizeof(struct sockaddr_in));
} }
if (nsize < 0 && errno != EAGAIN) {
perror("recvfrom: ");
}
} }
} }
} }