aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1997-01-08 19:00:32 +0000
committerEric S. Raymond <esr@thyrsus.com>1997-01-08 19:00:32 +0000
commitab7c3a1894f198a83d961459fb9c4387f4d9a634 (patch)
treedcda151223bdb462af5b9e53a4be58ce6149c669
parent08d9413c8e440aa38d7cee33dc035b2a2cd232c8 (diff)
downloadfetchmail-ab7c3a1894f198a83d961459fb9c4387f4d9a634.tar.gz
fetchmail-ab7c3a1894f198a83d961459fb9c4387f4d9a634.tar.bz2
fetchmail-ab7c3a1894f198a83d961459fb9c4387f4d9a634.zip
Cameron's speedup diff for socket.c.
svn path=/trunk/; revision=716
-rw-r--r--socket.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/socket.c b/socket.c
index af5018e4..1dd11a02 100644
--- a/socket.c
+++ b/socket.c
@@ -143,19 +143,27 @@ int SockWrite(char *buf, int size, int len, FILE *sockfp)
char *SockGets(char *buf, int len, FILE *sockfp)
{
- int rdlen = 0;
- char *cp = buf;
-
- while (--len)
- {
- if (read(fileno(sockfp), cp, 1) != 1)
- return((char *)NULL);
- else
- rdlen++;
- if (*cp++ == '\n')
- break;
- }
- *cp = 0;
+ char *p, *bp = buf;
+ int n;
+
+ if (--len < 1)
+ return NULL;
+ do {
+ if ((n = recv(fileno(sockfp), bp, len, MSG_PEEK)) == -1)
+ return NULL;
+ if ((p = memchr(bp, '\n', n)) != NULL)
+ {
+ if (read(fileno(sockfp), bp, ++p - bp) == -1)
+ return NULL;
+ *p = '\0';
+ return buf;
+ }
+ if ((n = read(fileno(sockfp), bp, n)) == -1)
+ return NULL;
+ bp += n;
+ len -= n;
+ } while (len);
+ *bp = '\0';
return buf;
}