diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1997-01-08 19:00:32 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1997-01-08 19:00:32 +0000 |
commit | ab7c3a1894f198a83d961459fb9c4387f4d9a634 (patch) | |
tree | dcda151223bdb462af5b9e53a4be58ce6149c669 | |
parent | 08d9413c8e440aa38d7cee33dc035b2a2cd232c8 (diff) | |
download | fetchmail-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.c | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -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; } |