diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-12-16 23:34:14 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-12-16 23:34:14 +0000 |
commit | f9fe7d50774c40e7bc637500188c9e130be0ea0a (patch) | |
tree | c9d736fb780c6caeefd73c97e188324e2c8df987 /socket.c | |
parent | 40107e575d94a69bc1584a1b41782996ee495493 (diff) | |
download | fetchmail-f9fe7d50774c40e7bc637500188c9e130be0ea0a.tar.gz fetchmail-f9fe7d50774c40e7bc637500188c9e130be0ea0a.tar.bz2 fetchmail-f9fe7d50774c40e7bc637500188c9e130be0ea0a.zip |
All right! True stdio buffering at last!
svn path=/trunk/; revision=631
Diffstat (limited to 'socket.c')
-rw-r--r-- | socket.c | 31 |
1 files changed, 7 insertions, 24 deletions
@@ -93,18 +93,8 @@ va_dcl { } /* - * FIXME: This needs to be recoded to use stdio, if that's possible. - * - * If you think these functions are too slow and inefficient, you're - * absolutely right. I wish I could figure out what to do about it. - * The ancestral popclient used static buffering here to cut down on the - * number of read(2) calls, but we can't do that because we can have - * two or more sockets open at a time. - * - * The right thing to do would be to use stdio for internal per-socket - * buffering here (which is why Socket() returns a file pointer) but - * this causes mysterious lossage. In case someone ever finds a way - * around this, a note on Carl Harris's original implementation said: + * In case we ever optimize this further, + * a note on Carl Harris's original implementation said: * * Size of buffer for internal buffering read function * don't increase beyond the maximum atomic read/write size for @@ -116,18 +106,11 @@ va_dcl { int SockWrite(char *buf, int len, FILE *sockfp) { - int n, wrlen = 0; + int n; - while (len) - { - n = write(fileno(sockfp), buf, len); - if (n <= 0) - return -1; - len -= n; - wrlen += n; - buf += n; - } - return wrlen; + if ((n = fwrite(buf, 1, len, sockfp)) < 1) + return -1; + return n; } int SockGets(char *buf, int len, FILE *sockfp) @@ -136,7 +119,7 @@ int SockGets(char *buf, int len, FILE *sockfp) while (--len) { - if (read(fileno(sockfp), buf, 1) != 1) + if ((*buf = fgetc(sockfp)) == EOF) return -1; else rdlen++; |