]> Pileus Git - ~andy/fetchmail/blobdiff - socket.c
Line-buffer all socket streams.
[~andy/fetchmail] / socket.c
index dbab92541a1ca16a8c21520ff135e842b73cf417..ddbf2f9351cf1a3fcef796d50700e674f2ae14f4 100644 (file)
--- a/socket.c
+++ b/socket.c
 #endif
 
 /*
- * 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
  * your sockets, or you'll take a potentially huge performance hit
- *
- * #define  INTERNAL_BUFSIZE   2048
- *
- * Note that stdio's 1024-byte default is just fine.
  */
+#define  INTERNAL_BUFSIZE      2048
 
 FILE *sockopen(char *host, int clientPort)
 {
@@ -53,7 +47,9 @@ FILE *sockopen(char *host, int clientPort)
     unsigned long inaddr;
     struct sockaddr_in ad;
     struct hostent *hp;
-    
+    FILE *fp;
+    static char sbuf[INTERNAL_BUFSIZE];
+
     memset(&ad, 0, sizeof(ad));
     ad.sin_family = AF_INET;
 
@@ -77,7 +73,9 @@ FILE *sockopen(char *host, int clientPort)
        close(sock);
         return (FILE *)NULL;
     }
-    return fdopen(sock, "r+");
+    fp = fdopen(sock, "r+");
+    setvbuf(fp, sbuf, _IOLBF, INTERNAL_BUFSIZE);
+    return(fp);
 }
 
 /* socket.c ends here */