aboutsummaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-12-25 10:37:09 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-12-25 10:37:09 +0000
commit481f2fe7871aca3171165913d603fc9ce8d12739 (patch)
tree113e6e1442a19763e655729d3160f27df8f575e0 /socket.c
parentf098021f7c4b021fde38bc91884e467ac9cde676 (diff)
downloadfetchmail-481f2fe7871aca3171165913d603fc9ce8d12739.tar.gz
fetchmail-481f2fe7871aca3171165913d603fc9ce8d12739.tar.bz2
fetchmail-481f2fe7871aca3171165913d603fc9ce8d12739.zip
Include test code.
svn path=/trunk/; revision=690
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/socket.c b/socket.c
index 0a0de3d7..7768c05f 100644
--- a/socket.c
+++ b/socket.c
@@ -34,6 +34,12 @@
#endif
#endif
+/*
+ * There are, in effect, two different implementations here. One
+ * uses read(2) and write(2) directly with no buffering, the other
+ * uses stdio with line buffering (for better throughput). Both
+ * are known to work under Linux.
+ */
/* #define USE_STDIO */
#ifdef USE_STDIO
@@ -116,19 +122,6 @@ va_dcl {
}
#ifndef USE_STDIO
-/*
- * 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 SockOpen() returns a file pointer) but
- * this causes mysterious lossage.
- */
int SockWrite(char *buf, int size, int len, FILE *sockfp)
{
@@ -164,6 +157,7 @@ char *SockGets(char *buf, int len, FILE *sockfp)
*cp = 0;
return buf;
}
+
#else
int SockWrite(char *buf, int size, int len, FILE *sockfp)
@@ -178,4 +172,18 @@ char *SockGets(char *buf, int len, FILE *sockfp)
#endif
+#ifdef MAIN
+/*
+ * Use the chargen service to test buffering directly.
+ */
+main()
+{
+ FILE *fp = SockOpen("localhost", 19);
+ char buf[80];
+
+ while (SockGets(buf, sizeof(buf)-1, fp))
+ SockWrite(buf, 1, strlen(buf), stdout);
+}
+#endif /* MAIN */
+
/* socket.c ends here */