timer in libinn

Alex Kiernan alexk at demon.net
Tue Feb 6 08:17:15 UTC 2001


Code to move timers into libinn, this seems to be doing the right
thing; lib/timer.c and include/timer.h should be attached. This should
cover both innfeed & innd. Still needs some docs writing, I'll get to
that today, with luck.

Index: configure.in
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/configure.in,v
retrieving revision 1.195
diff -u -r1.195 configure.in
--- configure.in	2001/02/06 01:11:31	1.195
+++ configure.in	2001/02/06 08:12:52
@@ -1132,6 +1135,7 @@
 AC_FUNC_MEMCMP
 AC_FUNC_VFORK
 AC_TYPE_SIGNAL
+AC_FUNC_ALLOCA
 
 dnl Source used by INN_FUNC_INET_NTOA
 define([_INN_FUNC_INET_NTOA_SOURCE],
@@ -1216,7 +1220,7 @@
 dnl Check for various other functions.
 AC_CHECK_FUNCS(atexit getpagesize getrlimit getrusage getspnam setbuffer \
                sigaction setrlimit setsid socketpair statvfs strncasecmp \
-               strtoul symlink sysconf)
+               strtoul symlink sysconf gethrtime)
 
 dnl Find a way to get the file descriptor limit.
 if test x"$ac_cv_func_getrlimit" = xno ; then
Index: innfeed/Makefile
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/innfeed/Makefile,v
retrieving revision 1.44
diff -u -r1.44 Makefile
--- innfeed/Makefile	2001/02/05 22:42:27	1.44
+++ innfeed/Makefile	2001/02/06 08:12:52
@@ -8,7 +8,7 @@
 
 SOURCES		= article.c buffer.c config_l.c config_y.c \
 		  endpoint.c host.c innlistener.c main.c misc.c \
-		  startinnfeed.c tape.c timer.c version.c
+		  startinnfeed.c tape.c version.c
 
 INCLUDES	= article.h buffer.h configfile.h config_y.h connection.h \
 		  endpoint.h host.h innfeed.h innlistener.h misc.h msgs.h \
@@ -17,7 +17,7 @@
 # The objects linked into innfeed.  All SOURCES except startinnfeed.
 OBJECTS		= article.o buffer.o config_l.o config_y.o \
 		  endpoint.o host.o innlistener.o main.o misc.o tape.o \
-		  timer.o version.o
+		  version.o
 
 INSTALLED	= $(D)$(PATHBIN)/innfeed \
 		  $(D)$(PATHBIN)/procbatch \
@@ -145,6 +145,4 @@
 tape.o: tape.c innfeed.h ../include/config.h ../include/inn/defines.h \
  ../include/clibrary.h ../include/libinn.h article.h misc.h \
  configfile.h endpoint.h msgs.h tape.h
-timer.o: timer.c ../include/clibrary.h ../include/config.h \
- ../include/inn/defines.h innfeed.h
 version.o: version.c
Index: innfeed/endpoint.c
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/innfeed/endpoint.c,v
retrieving revision 1.18
diff -u -r1.18 endpoint.c
--- innfeed/endpoint.c	2001/01/18 22:01:07	1.18
+++ innfeed/endpoint.c	2001/02/06 08:12:52
@@ -74,6 +74,10 @@
 #include "host.h"
 #include "msgs.h"
 
+static const char *const timer_name[] = {
+  "idle", "blstats", "stsfile", "newart", "readart", "prepart", "read",
+  "write", "cb"
+};
 
 #if defined (__bsdi__) && (defined (_ANSI_SOURCE) || defined (_POSIX_SOURCE))
   /* why do I have to do this???? */
@@ -626,11 +630,13 @@
   fd_set rSet ;
   fd_set wSet ;
   fd_set eSet ;
+  unsigned long last_summary ;
 
   keepSelecting = 1 ;
   xsignal (SIGPIPE, pipeHandler) ;
 
-  TMRinit();
+  if (innconf->timer)
+    TMRinit(TMR_MAX);
   while (keepSelecting)
     {
       struct timeval timeout ;
@@ -673,7 +679,15 @@
       TMRstop(TMR_IDLE);
 
       timePasses () ;
-      TMRmainloophook();
+      if (innconf->timer)
+        {
+	  unsigned long now = TMRnow () ;
+	  if (now - last_summary > (innconf->timer * 1000))
+	    {
+	      TMRsummary (timer_name) ;
+	      last_summary = now;
+	    }
+	}
       
       if (sval == 0 && twait == NULL)
         die ("No fd's ready and no timeouts") ;
Index: innfeed/innfeed.h
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/innfeed/innfeed.h,v
retrieving revision 1.4
diff -u -r1.4 innfeed.h
--- innfeed/innfeed.h	2001/01/18 22:01:09	1.4
+++ innfeed/innfeed.h	2001/02/06 08:12:52
@@ -33,6 +33,8 @@
 #if ! defined ( innfeed_h__ )
 #define innfeed_h__
 
+#include "timer.h"
+
 /**********************************************************************/
 /*                     Application specific defines                   */
 /**********************************************************************/
@@ -263,8 +265,9 @@
 
 /* some timer constants */
 
-typedef enum { TMR_IDLE, TMR_BACKLOGSTATS, TMR_STATUSFILE, TMR_NEWARTICLE,
-  TMR_READART, TMR_PREPART, TMR_READ, TMR_WRITE, TMR_CALLBACK, TMR_MAX
+typedef enum { TMR_IDLE = TMR_APPLICATION, TMR_BACKLOGSTATS,
+  TMR_STATUSFILE, TMR_NEWARTICLE, TMR_READART, TMR_PREPART, TMR_READ,
+  TMR_WRITE, TMR_CALLBACK, TMR_MAX
 } TMRTYPE;
 
 #endif /* innfeed_h__ */
Index: innd/Makefile
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/innd/Makefile,v
retrieving revision 1.49
diff -u -r1.49 Makefile
--- innd/Makefile	2001/02/05 22:42:24	1.49
+++ innd/Makefile	2001/02/06 08:12:52
@@ -8,12 +8,12 @@
 
 SOURCES		= art.c cc.c chan.c his.c icd.c innd.c inndstart.c lc.c \
 		  nc.c newsfeeds.c ng.c perl.c proc.c python.c rc.c site.c \
-		  status.c tcl.c timer.c util.c wip.c
+		  status.c tcl.c util.c wip.c
 
 # The objects that are linked into innd.  All SOURCES except inndstart.
 OBJECTS		= art.o cc.o chan.o his.o icd.o innd.o lc.o nc.o \
 		  newsfeeds.o ng.o perl.o proc.o python.o rc.o site.o \
-		  status.o tcl.o timer.o util.o wip.o
+		  status.o tcl.o util.o wip.o
 
 INSTALLED	= $(D)$(PATHBIN)/innd \
 		  $(D)$(PATHBIN)/inndstart
@@ -170,10 +170,6 @@
  ../include/nntp.h ../include/paths.h ../include/storage.h
 tcl.o: tcl.c ../include/config.h ../include/inn/defines.h \
  ../include/clibrary.h innd.h ../include/portable/time.h \
- ../include/dbz.h ../include/libinn.h ../include/macros.h \
- ../include/nntp.h ../include/paths.h ../include/storage.h
-timer.o: timer.c ../include/clibrary.h ../include/config.h \
- ../include/inn/defines.h innd.h ../include/portable/time.h \
  ../include/dbz.h ../include/libinn.h ../include/macros.h \
  ../include/nntp.h ../include/paths.h ../include/storage.h
 util.o: util.c ../include/config.h ../include/inn/defines.h \
Index: innd/chan.c
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/innd/chan.c,v
retrieving revision 1.51
diff -u -r1.51 chan.c
--- innd/chan.c	2001/02/02 17:55:35	1.51
+++ innd/chan.c	2001/02/06 08:12:52
@@ -26,6 +26,12 @@
 # define ENOTTY 0
 #endif
 
+static const char * const timer_name[] = {
+    "idle", "artclean", "artwrite", "artctrl", "artcncl",
+    "sitesend", "overv", "perl", "python", "nntpread", "artparse",
+    "artlog", "datamove"
+};
+
 /* Minutes - basically, keep the connection open but idle */
 #define PAUSE_BEFORE_DROP               5
 
@@ -945,8 +951,10 @@
     char		*p;
     time_t		LastUpdate;
     HDRCONTENT		*hc;
+
+    if (innconf->timer)
+	TMRinit(TMR_MAX);
 
-    TMRinit();
     STATUSinit();
     
     LastUpdate = GetTimeInfo(&Now) < 0 ? 0 : Now.time;
@@ -958,8 +966,17 @@
 	MyRead = RCHANmask;
 	MyWrite = WCHANmask;
 	MyTime = TimeOut;
-        i = TMRmainloophook();
-        if (i != 0) MyTime.tv_sec = i;
+	if (innconf->timer) {
+	    unsigned long now = TMRnow();
+
+	    if (now >= (unsigned int)innconf->timer * 1000) {
+		TMRsummary(timer_name);
+		MyTime.tv_sec = innconf->timer;
+	    }
+	    else {
+		MyTime.tv_sec = innconf->timer - now / 1000;
+	    }
+	}
 	TMRstart(TMR_IDLE);
 	count = select(CHANlastfd + 1, &MyRead, &MyWrite, NULL, &MyTime);
 	TMRstop(TMR_IDLE);
Index: innd/innd.h
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/innd/innd.h,v
retrieving revision 1.78
diff -u -r1.78 innd.h
--- innd/innd.h	2001/02/05 22:00:43	1.78
+++ innd/innd.h	2001/02/06 08:12:52
@@ -44,6 +44,7 @@
 #include "nntp.h"
 #include "paths.h"
 #include "storage.h"
+#include "timer.h"
 
 /* TCL defines EXTERN, so undef it after inclusion since we use it. */
 #if DO_TCL
@@ -494,14 +495,10 @@
 
 /*
 **  Supported timers.  If you add new timers to this list, also add them to
-**  the list of tags at the top of timer.c.
+**  the list of tags in chan.c.
 */
 enum timer {
-  TMR_IDLE,	/* Server is completely idle.		*/
-  TMR_HISHAVE,	/* Looking up ID in history (yes/no).	*/
-  TMR_HISGREP,	/* Looking up ID in history (data).	*/
-  TMR_HISWRITE,	/* Writing to history.			*/
-  TMR_HISSYNC,	/* Syncing history to disk.		*/
+  TMR_IDLE = TMR_APPLICATION,	/* Server is completely idle.		*/
   TMR_ARTCLEAN,	/* Analyzing an incoming article.	*/
   TMR_ARTWRITE,	/* Writing an article.			*/
   TMR_ARTCTRL,	/* Processing a control message.	*/
@@ -770,12 +767,6 @@
 
 extern void		STATUSinit(void);
 extern void		STATUSmainloophook(void);
-
-/* timer.c */
-extern void		TMRinit(void);
-extern int		TMRmainloophook(void);
-extern void		TMRstart(enum timer timer);
-extern void		TMRstop(enum timer timer);
 
 extern void		WIPsetup(void);
 extern WIP	    *	WIPnew(const char *messageid, CHANNEL *cp);
Index: lib/Makefile
===================================================================
RCS file: /upstream-repositories/inn-cvs.isc.org/inn/lib/Makefile,v
retrieving revision 1.65
diff -u -r1.65 Makefile
--- lib/Makefile	2001/02/05 22:42:30	1.65
+++ lib/Makefile	2001/02/06 08:12:52
@@ -13,7 +13,7 @@
 	radix32.c readin.c remopen.c reservedfd.c resource.c rwlock.c \
 	sendarticle.c sendpass.c setenv.c strcasecmp.c strerror.c strspn.c \
 	strtok.c tempname.c wildmat.c version.c xfopena.c xmalloc.c \
-	xsignal.c xwrite.c
+	xsignal.c xwrite.c timer.c
 
 OBJECTS = $(LIBOBJS) \
 	argparse.o cleanfrom.o clientactive.o clientlib.o concat.o \
@@ -22,7 +22,8 @@
 	gettime.o grpalias.o hash.o inndcomm.o localopen.o lockfile.o \
 	makedir.o md5.o parsedate.o qio.o radix32.o readin.o remopen.o \
 	reservedfd.o resource.o rwlock.o sendarticle.o sendpass.o \
-	tempname.o wildmat.o version.o xfopena.o xmalloc.o xsignal.o xwrite.o
+	tempname.o wildmat.o version.o xfopena.o xmalloc.o xsignal.o \
+	xwrite.o timer.o
 
 LOBJECTS= $(OBJECTS:.o=.lo)
 

-- 
Alex Kiernan, Principal Engineer, Development, Thus PLC




More information about the inn-patches mailing list