warp-vpn

simple point to point tunnel
git clone git://git.2f30.org/warp-vpn.git
Log | Files | Refs | README

commit e275139b3d1a5e182d8f1018ecbd1f228c55dd18
parent dc08dd9d1644071f7b323fbed40205bf905dc2e0
Author: sin <sin@2f30.org>
Date:   Fri Apr  1 16:32:49 +0100

no need for infinite loop

Diffstat:
stun.c | 41++++++++++++++++++++---------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/stun.c b/stun.c @@ -513,29 +513,28 @@ challenge(int netfd) pack64(buf, n); if (writenet(netfd, buf, sizeof(uint64_t)) <= 0) return -1; - for (;;) { - pfd[0].fd = netfd; - pfd[0].events = POLLIN; - ret = poll(pfd, 1, RCVTIMEO); - if (ret < 0) { - logwarn("poll failed"); - return -1; - } else if (ret == 0) { - logwarn("challenge-response timed out"); - return -1; - } - if (pfd[0].revents & (POLLERR | POLLNVAL)) - logerr("bad fd in poll set"); + pfd[0].fd = netfd; + pfd[0].events = POLLIN; + ret = poll(pfd, 1, RCVTIMEO); + if (ret < 0) { + logwarn("poll failed"); + return -1; + } else if (ret == 0) { + logwarn("challenge-response timed out"); + return -1; + } - if (pfd[0].revents & (POLLIN | POLLHUP)) { - ret = readnet(netfd, buf, sizeof(uint64_t)); - if (ret <= 0 || ret == BADPKT) - return -1; - reply = unpack64(buf); - if (n + 1 == reply) - return 0; - } + if (pfd[0].revents & (POLLERR | POLLNVAL)) + logerr("bad fd in poll set"); + + if (pfd[0].revents & (POLLIN | POLLHUP)) { + ret = readnet(netfd, buf, sizeof(uint64_t)); + if (ret <= 0 || ret == BADPKT) + return -1; + reply = unpack64(buf); + if (n + 1 == reply) + return 0; } return -1; }