#ifndef LINT static char *rcsid="$Id: mainloop.c,v 1.5 1998/07/28 17:51:53 crosser Exp $"; #endif /* $Log: mainloop.c,v $ Revision 1.5 1998/07/28 17:51:53 crosser make 64bit architecure happy Revision 1.4 1998/07/05 00:26:18 crosser Change copyright Revision 1.3 1998/07/02 18:01:15 crosser change error reporting to syslog Revision 1.2 1998/07/01 13:39:18 crosser make it work on Solaris Revision 1.1 1998/07/01 05:01:22 crosser Initial revision */ /* WHAT IS IT: Implementation of experimental "whoson" protocol AUTHOR: Eugene G. Crosser COPYRIGHT: Public domain */ #include "config.h" #include #include #include #ifdef HAVE_SYS_SELECT_H #include #endif #include #include #include #include "whosond.h" #include "report.h" void mainloop(struct _evdesc (*evvec[]) (int fd, void *priv), void *priv[]) { fd_set rfds,wfds,efds; struct timeval seltimer; int i,maxfd,rc; struct _evdesc evdesc; time_t now,until; time_t ttl[FD_SETSIZE]; maxfd=0; for (i=0;i now)) until=ttl[i]; if (ttl[i] && (ttl[i] <= now)) { ERRLOG((LOG_INFO,"kill fd=%d\n",i)) (void)evvec[i](-i,priv[i]); evvec[i]=NULL; priv[i]=NULL; ttl[i]=0; } else FD_SET(i,&rfds); } seltimer.tv_sec=until-now; seltimer.tv_usec=0; #if (DPRINT) for (i=0;i= 0) (void)time(&now); if (rc > 0) { for (i=0;i<=maxfd;i++) if (FD_ISSET(i,&rfds)) { if (evvec[i]) { evdesc=evvec[i](i,priv[i]); if (evdesc.fd >= 0) { evvec[evdesc.fd]=evdesc.evproc; if (evdesc.ttl) ttl[evdesc.fd]= now+evdesc.ttl; priv[evdesc.fd]=evdesc.priv; } if (evdesc.fd > maxfd) maxfd=evdesc.fd; } else { ERRLOG((LOG_WARNING,"spurious fd=%d\n",i)) } } } else if (rc == 0) { printf("timeout\n"); } else { ERRLOG((LOG_ERR,"select failure: %m")) } } }