aboutsummaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-12-16 23:34:14 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-12-16 23:34:14 +0000
commitf9fe7d50774c40e7bc637500188c9e130be0ea0a (patch)
treec9d736fb780c6caeefd73c97e188324e2c8df987 /socket.c
parent40107e575d94a69bc1584a1b41782996ee495493 (diff)
downloadfetchmail-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.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/socket.c b/socket.c
index f21cf1fa..baf4c70a 100644
--- a/socket.c
+++ b/socket.c
@@ -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++;