aboutsummaryrefslogtreecommitdiffstats
path: root/socket.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1996-10-31 09:06:50 +0000
committerEric S. Raymond <esr@thyrsus.com>1996-10-31 09:06:50 +0000
commit1d95131a945586b4eb6596583c364e5eb60025a8 (patch)
treef329436f26f8193dd6dab06eeb76ebeb4736b416 /socket.c
parentc2aeabfb67891889fde49b70a5bee8dbfeb7b8de (diff)
downloadfetchmail-1d95131a945586b4eb6596583c364e5eb60025a8.tar.gz
fetchmail-1d95131a945586b4eb6596583c364e5eb60025a8.tar.bz2
fetchmail-1d95131a945586b4eb6596583c364e5eb60025a8.zip
Document the lossage.
svn path=/trunk/; revision=455
Diffstat (limited to 'socket.c')
-rw-r--r--socket.c83
1 files changed, 45 insertions, 38 deletions
diff --git a/socket.c b/socket.c
index 9461eee8..6dd77f55 100644
--- a/socket.c
+++ b/socket.c
@@ -1,12 +1,6 @@
/*
* socket.c -- socket library functions
*
- * These were designed and coded by Carl Harris <ceharris@mal.com>
- * and are essentially unchanged from the ancestral popclient.
- *
- * The file pointer arguments are currently misleading -- there
- * is only one shared internal buffer for all sockets.
- *
* For license terms, see the file COPYING in this directory.
*/
@@ -19,8 +13,6 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
#if defined(STDC_HEADERS)
#include <string.h>
#include <stdlib.h>
@@ -36,12 +28,6 @@
#include <errno.h>
#include "socket.h"
-/* 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
-
FILE *Socket(host, clientPort)
char *host;
int clientPort;
@@ -74,6 +60,51 @@ int clientPort;
return fdopen(sock, "r+");
}
+
+#if defined(HAVE_STDARG_H)
+int SockPrintf(FILE *sockfp, char* format, ...)
+{
+#else
+int SockPrintf(sockfp,format,va_alist)
+FILE *sockfp;
+char *format;
+va_dcl {
+#endif
+
+ va_list ap;
+ char buf[8192];
+
+#if defined(HAVE_STDARG_H)
+ va_start(ap, format) ;
+#else
+ va_start(ap);
+#endif
+ vsprintf(buf, format, ap);
+ va_end(ap);
+ return SockWrite(buf, strlen(buf), sockfp);
+
+}
+
+/*
+ * 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 the 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
+ *
+ */
+
int SockWrite(buf,len,sockfp)
char *buf;
int len;
@@ -115,28 +146,4 @@ FILE *sockfp;
return rdlen;
}
-#if defined(HAVE_STDARG_H)
-int SockPrintf(FILE *sockfp, char* format, ...)
-{
-#else
-int SockPrintf(sockfp,format,va_alist)
-FILE *sockfp;
-char *format;
-va_dcl {
-#endif
-
- va_list ap;
- char buf[8192];
-
-#if defined(HAVE_STDARG_H)
- va_start(ap, format) ;
-#else
- va_start(ap);
-#endif
- vsprintf(buf, format, ap);
- va_end(ap);
- return SockWrite(buf, strlen(buf), sockfp);
-
-}
-
/* socket.c ends here */