From e2914b619afd334ae57f10e8af35c9c43088f24b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 21 Dec 1996 19:17:03 +0000 Subject: Include test code. svn path=/trunk/; revision=672 --- Makefile.in | 11 +++++++++++ acconfig.h | 3 +++ configure.in | 2 +- socket.c | 33 +++++++++++++++++++++++++++------ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Makefile.in b/Makefile.in index e7dea005..21153574 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 '' rather than # ``#include "config.h"''. So we add the explicit dependency to make sure. diff --git a/acconfig.h b/acconfig.h index 54458058..d6a1399b 100644 --- a/acconfig.h +++ b/acconfig.h @@ -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 + /* Leave that blank line there!! Autoheader needs it. If you're adding to this file, keep in mind: diff --git a/configure.in b/configure.in index 2bda847b..d988c620 100644 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/socket.c b/socket.c index 9bfc5485..fbe26ef7 100644 --- 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 */ -- cgit v1.2.3