aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--socket.c14
1 files 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';