stun

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

commit ea41c51a5b7a93ba147663d1439695a927b1f80f
parent 6b59492cf23acbdfdea0cbaceefa0a5dbef39756
Author: sin <sin@2f30.org>
Date:   Tue, 12 Apr 2016 15:33:37 +0100

get rid of the inner loops

Diffstat:
Mnetpkt.c | 42+++++++++++++++++-------------------------
1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/netpkt.c b/netpkt.c @@ -93,24 +93,20 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) state = STATENONCE; break; case STATENONCE: - while (rbufrem > 0) { - if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) - goto out; - rbuftotal += n; - rbufrem -= n; - } + if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) + goto out; + rbuftotal += n; + rbufrem -= n; if (rbufrem == 0) { rbufrem = HDRLEN; state = STATEHDR; } break; case STATEHDR: - while (rbufrem > 0) { - if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) - goto out; - rbuftotal += n; - rbufrem -= n; - } + if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) + goto out; + rbuftotal += n; + rbufrem -= n; if (rbufrem == 0) { n = unpack16(&rbuf[noncelen]); if (n > ptlen) { @@ -122,24 +118,20 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) } break; case STATEPAYLOAD: - while (rbufrem > 0) { - if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) - goto out; - rbuftotal += n; - rbufrem -= n; - } + if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) + goto out; + rbuftotal += n; + rbufrem -= n; if (rbufrem == 0) { rbufrem = taglen; state = STATETAG; } break; case STATETAG: - while (rbufrem > 0) { - if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) - goto out; - rbuftotal += n; - rbufrem -= n; - } + if ((n = read(fd, rbuf + rbuftotal, rbufrem)) <= 0) + goto out; + rbuftotal += n; + rbufrem -= n; if (rbufrem == 0) state = STATEDECRYPT; break; @@ -161,7 +153,7 @@ netread(int fd, unsigned char *pt, size_t ptlen, size_t *outlen) break; } } - return PKTFAILED; + return PKTPARTIAL; out: if (n == 0) return PKTFAILED;