speed up reading of messages by reducing system call load
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 13 Apr 1994 07:11:50 +0000 (23:11 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Wed, 13 Apr 1994 07:11:50 +0000 (23:11 -0800)
SCCS-vsn: usr.sbin/sendmail/src/collect.c 8.10
SCCS-vsn: usr.sbin/sendmail/src/util.c 8.38

usr/src/usr.sbin/sendmail/src/collect.c
usr/src/usr.sbin/sendmail/src/util.c

index bd201e6..51fb223 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)collect.c  8.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)collect.c  8.10 (Berkeley) %G%";
 #endif /* not lint */
 
 # include <errno.h>
 #endif /* not lint */
 
 # include <errno.h>
@@ -67,6 +67,9 @@ maketemp(from)
        if (smtpmode)
                message("354 Enter mail, end with \".\" on a line by itself");
 
        if (smtpmode)
                message("354 Enter mail, end with \".\" on a line by itself");
 
+       /* set global timer to monitor progress */
+       sfgetset(TimeOuts.to_datablock);
+
        /*
        **  Try to read a UNIX-style From line
        */
        /*
        **  Try to read a UNIX-style From line
        */
@@ -258,6 +261,9 @@ readerr:
                inputerr = TRUE;
        }
 
                inputerr = TRUE;
        }
 
+       /* reset global timer */
+       sfgetset((time_t) 0);
+
        if (fflush(tf) != 0)
                tferror(tf, e);
        if (fsync(fileno(tf)) < 0 || fclose(tf) < 0)
        if (fflush(tf) != 0)
                tferror(tf, e);
        if (fsync(fileno(tf)) < 0 || fclose(tf) < 0)
index 80a8bf8..65e55ba 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     8.37 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     8.38 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -871,6 +871,9 @@ xfclose(fp, a, b)
 
 static jmp_buf CtxReadTimeout;
 static int     readtimeout();
 
 static jmp_buf CtxReadTimeout;
 static int     readtimeout();
+static EVENT   *GlobalTimeout = NULL;
+static bool    EnableTimeout = FALSE;
+static int     ReadProgress;
 
 char *
 sfgets(buf, siz, fp, timeout, during)
 
 char *
 sfgets(buf, siz, fp, timeout, during)
@@ -908,7 +911,10 @@ sfgets(buf, siz, fp, timeout, during)
 #endif
                        return (NULL);
                }
 #endif
                        return (NULL);
                }
-               ev = setevent(timeout, readtimeout, 0);
+               if (GlobalTimeout == NULL)
+                       ev = setevent(timeout, readtimeout, 0);
+               else
+                       EnableTimeout = TRUE;
        }
 
        /* try to read */
        }
 
        /* try to read */
@@ -923,7 +929,10 @@ sfgets(buf, siz, fp, timeout, during)
        }
 
        /* clear the event if it has not sprung */
        }
 
        /* clear the event if it has not sprung */
-       clrevent(ev);
+       if (GlobalTimeout == NULL)
+               clrevent(ev);
+       else
+               EnableTimeout = FALSE;
 
        /* clean up the books and exit */
        LineNumber++;
 
        /* clean up the books and exit */
        LineNumber++;
@@ -942,10 +951,44 @@ sfgets(buf, siz, fp, timeout, during)
        return (buf);
 }
 
        return (buf);
 }
 
+void
+sfgetset(timeout)
+       time_t timeout;
+{
+       /* cancel pending timer */
+       if (GlobalTimeout != NULL)
+       {
+               clrevent(GlobalTimeout);
+               GlobalTimeout = NULL;
+       }
+
+       /* schedule fresh one if so requested */
+       if (timeout != 0)
+       {
+               ReadProgress = LineNumber;
+               GlobalTimeout = setevent(timeout, readtimeout, timeout);
+       }
+}
+
 static
 static
-readtimeout()
+readtimeout(timeout)
+       time_t timeout;
 {
 {
-       longjmp(CtxReadTimeout, 1);
+       /* terminate if ordinary timeout */
+       if (GlobalTimeout == NULL)
+               longjmp(CtxReadTimeout, 1);
+
+       /* terminate if no progress was made -- reset state */
+       if (EnableTimeout && (LineNumber <= ReadProgress))
+       {
+               EnableTimeout = FALSE;
+               GlobalTimeout = NULL;
+               longjmp(CtxReadTimeout, 2);
+       }
+
+       /* schedule a new timeout */
+       GlobalTimeout = NULL;
+       sfgetset(timeout);
 }
 \f/*
 **  FGETFOLDED -- like fgets, but know about folded lines.
 }
 \f/*
 **  FGETFOLDED -- like fgets, but know about folded lines.