/* * TIME.C * * Handle IPC alert functions & timekeeping for connect and idle time. */ #include "dnet.h" #include #include #define TICKSIZE 10 /* 10 second intervals */ static long TickIdle; static long TickConnect; static long AlertIdle; static long AlertConnect; static char AIWho[64]; /* app-name to alert */ static char ACWho[64]; /* app-name to alert */ /* * CTO: Idle timeout (check carrier) * */ do_cto(ior) IOT *ior; { if (Cto_act) { AbortIO(ior); WaitIO(ior); } ior->tr_time.tv_secs = TICKSIZE; ior->tr_time.tv_micro = 0; SendIO(ior); Cto_act = 1; if (Cd) { ++TickConnect; ++TickIdle; } if (DDebug) printf("I/C: %ld %ld (%ld %ld)\n", TickIdle, TickConnect, AlertIdle, AlertConnect); if (AlertConnect && TickConnect > AlertConnect) /* alert ipc msg */ doipcmsg(ACWho, "\0connalert", 11); if (AlertIdle && TickIdle > AlertIdle) /* alert ipc msg */ doipcmsg(AIWho, "\0idlealert", 11); } /* * Idle/Connect time & alerter vars. IPC: * resetidle * alertidle (N in seconds) * alertconn (N in seconds) */ ResetIdle() { TickIdle = 0; } ResetConnect() { TickConnect = 0; } LessConnect(n) { TickConnect -= n; if (TickConnect < 0) TickConnect = 0; } SetConnectAlert(n, who) char *who; { AlertConnect = (n+(TICKSIZE-1))/TICKSIZE; ACWho[0] = 0; if (who) strcpy(ACWho, who); } SetIdleAlert(n, who) char *who; { AlertIdle = (n+(TICKSIZE-1))/TICKSIZE; AIWho[0] = 0; if (who) strcpy(AIWho, who); } GetIdle() { return(TickIdle * TICKSIZE); } GetConnect() { return(TickConnect * TICKSIZE); } doipcmsg(app, cmd, len) char *app; char *cmd; short len; { register IPCMSG *msg; register long res = 1; IPCMSG *SendIPC(); if (DDebug) printf("IPC: <%s><%s> = ", app, cmd+1); fflush(stdout); if (msg = SendIPC(app, cmd, len, 0)) { WaitMsg(msg); res = msg->Error; FreeIPC(msg); } if (DDebug) printf("%ld\n", res); }