aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--socket.c16
2 files changed, 9 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 3298f55a..14888171 100644
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,8 @@ bugs --
* Restored portability to Solaris.
+* Force line-buffering on socket streams (Linux apparently defaults to this).
+
------------------------------------------------------------------------------
features --
diff --git a/socket.c b/socket.c
index dbab9254..ddbf2f93 100644
--- a/socket.c
+++ b/socket.c
@@ -35,17 +35,11 @@
#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 */