]> Pileus Git - ~andy/fetchmail/commitdiff
Include test code.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 21 Dec 1996 19:17:03 +0000 (19:17 -0000)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 21 Dec 1996 19:17:03 +0000 (19:17 -0000)
svn path=/trunk/; revision=672

Makefile.in
acconfig.h
configure.in
socket.c

index e7dea00510967786f56cfab562d325ba89681b60..21153574aa9ec23eb234253766bb717129eba531 100644 (file)
@@ -154,6 +154,7 @@ fetchmail.spec: $(srcdir)/Makefile.in $(srcdir)/specgen.sh
 clean: 
        -rm -f fetchmail *.o core fetchmail.dvi \
               rcfile_l.c rcfile_y.h rcfile_y.c fetchmail.tar fetchmail.tar.gz
+       -rm -f linetest[12]
 
 distclean: clean 
        -rm -f Makefile config.h
@@ -179,6 +180,9 @@ stamp-config: config.status $(srcdir)/config.h.in
 configure: configure.in
        autoconf $(ACFLAGS)
 
+config.h.in: acconfig.h
+       autoheader $(ACFLAGS)
+
 # This tells versions [3.59,3.63) of GNU make not to export all variables.
 .NOEXPORT:
 
@@ -215,6 +219,13 @@ fetchmail-$(VERS).tar: $(all)
 fetchmail-$(VERS).tar.gz: fetchmail-$(VERS).tar
        gzip -f fetchmail-$(VERS).tar
 
+# Test for stdio line-buffering lossage on sockets
+linetest1: socket.c
+       $(CC) -g -I. -DMAIN socket.c -o linetest1       # Use setlinebuf
+linetest2: socket.c
+       $(CC) -g -I. -DMAIN -D__SETVBUF_WORKS_OK__=1 socket.c -o linetest2      # Use setvnbuf
+
+
 # The automatically generated dependencies below may omit config.h
 # because it is included with ``#include <config.h>'' rather than
 # ``#include "config.h"''.  So we add the explicit dependency to make sure.
index 54458058ece4063bc6bea07fe8c2d2a48d9cede0..d6a1399b88f94d219977f800f701c22bf7a6b208 100644 (file)
@@ -32,6 +32,9 @@
 /* Define if you have GNU's getopt family of functions.  */
 #undef HAVE_GETOPTLONG
 
+/* Define if you have setlinebuf(3) */
+#undef HAVE_SETLINEBUF
+
 \f
 /* Leave that blank line there!!  Autoheader needs it.
    If you're adding to this file, keep in mind:
index 2bda847b3b936862d3d346c0f5e40457b91c13c9..d988c62020ffb9539320cfdd86d2da4460432821 100644 (file)
@@ -77,7 +77,7 @@ AC_SUBST(EXTRASRC)
 AC_SUBST(EXTRAOBJ)
 
 AC_CHECK_FUNCS(tcsetattr stty setsid seteuid gethostbyname res_search herror \
-  strrchr strerror)
+  strrchr strerror setlinebuf)
 
 dnl AC_FUNC_SETVBUF_REVERSED
 
index 9bfc54851329fb0173a6b422bbded2867859bf7c..fbe26ef74754a6fdaa5db845abf7a791b20df107 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -48,7 +48,6 @@ FILE *sockopen(char *host, int clientPort)
     struct sockaddr_in ad;
     struct hostent *hp;
     FILE *fp;
-    static char sbuf[INTERNAL_BUFSIZE];
 
     memset(&ad, 0, sizeof(ad));
     ad.sin_family = AF_INET;
@@ -75,17 +74,39 @@ FILE *sockopen(char *host, int clientPort)
     }
     fp = fdopen(sock, "r+");
 
-#ifdef FOO
+#ifdef __SETVBUF_WORKS_OK__
     /*
-     * For unknown reasons, this results in horrible lossage.
+     * For unknown reasons, this results in horrible lossage under Linux.
      * To see this, condition in this line, generate a test pattern
      * of 8K, fetch it, and watch it garble the test pattern.
-     * I think there's a bug in stdio lurking here.
+     * I think there's a bug in Linux stdio lurking here.
      */
-    setvbuf(fp, sbuf, _IOLBF, INTERNAL_BUFSIZE);
-#endif /* FOO */
+    {
+       static char sbuf[INTERNAL_BUFSIZE];
+       setvbuf(fp, sbuf, _IOLBF, INTERNAL_BUFSIZE);
+    }
+#endif /* __SETVBUF_WORKS_OK__ */
+
+#if !defined(__SETVBUF_WORKS_OK__) && defined(HAVE_SETLINEBUF)
+    /* this on the other hand works OK under Linux */
+    setlinebuf(fp);
+#endif
 
     return(fp);
 }
 
+#ifdef MAIN
+/*
+ * Use the chargen service to test buffering directly.
+ */
+main()
+{
+    FILE       *fp = sockopen("localhost", 19);
+    char       buf[80];
+
+    while (fgets(buf, sizeof(buf)-1, fp))
+       fputs(buf, stdout);
+}
+#endif /* MAIN */
+
 /* socket.c ends here */