From 44ffea62b3a6e0ed3d60cf817fb24df67e11ff81 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Wed, 14 May 1997 13:51:52 +0000 Subject: Cleaner version of SockRead. svn path=/trunk/; revision=995 --- socket.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/socket.c b/socket.c index 1df8061f..71b7d543 100644 --- a/socket.c +++ b/socket.c @@ -129,22 +129,20 @@ int SockRead(int sock, char *buf, int len) */ readlen = 0; - /* return value of 0 is EOF, < 0 is error */ if ((n = recv(sock, bp, len, MSG_PEEK)) <= 0) return(-1); if ((p = memchr(bp, '\n', n)) != NULL) - { - if ((n = read(sock, bp, ++p - bp)) == -1) - return(-1); - readlen += n; - *p = '\0'; - return readlen; - } + n = ++p - bp; if ((n = read(sock, bp, n)) == -1) return(-1); readlen += n; bp += n; len -= n; + if (p) + { + *p = '\0'; + break; + } } while (len); *bp = '\0'; -- cgit v1.2.3