diff --git a/Changes b/Changes index 5091ae319..60a5b7be6 100644 --- a/Changes +++ b/Changes @@ -496,3 +496,4 @@ seen. gmtime warning still there - Removed ce_vardatanum (wasted CPU and memory) - Added code to make the config parser try and stay alive when an error is encountered - Added events code and converted some stuff to events +- Converted htmcalc/lcf to events diff --git a/include/events.h b/include/events.h index 5516f9f66..7841a702a 100644 --- a/include/events.h +++ b/include/events.h @@ -21,9 +21,6 @@ #define EVENT(x) void (x) (void *data) -void EventAdd(char *name, long every, long howmany, - vFP event, void *data); - typedef struct _event Event; struct _event { @@ -35,3 +32,17 @@ struct _event { void *data; time_t last; }; + +void EventAdd(char *name, long every, long howmany, + vFP event, void *data); +Event *EventDel(char *name); + +Event *EventFind(char *name); + +void EventModEvery(char *name, int every); + +void DoEvents(void); + +void EventStatus(aClient *sptr); + +void SetupEvents(void); \ No newline at end of file diff --git a/include/h.h b/include/h.h index 254fab637..e55df0849 100644 --- a/include/h.h +++ b/include/h.h @@ -51,6 +51,20 @@ extern time_t timeofday; #define get_sendq(x) ((x)->class ? (x)->class->sendq : MAXSENDQLENGTH) +#ifndef NO_FDLIST +extern float currentrate; +extern float currentrate2; /* outgoing */ +extern float highest_rate; +extern float highest_rate2; +extern int lifesux; +extern int LRV; +extern TS LCF; +extern int currlife; +extern int HTMLOCK; +extern int noisy_htm; +extern long lastsendK, lastrecvK; +#endif + /* * Configuration linked lists */ diff --git a/include/proto.h b/include/proto.h index 88dbe065a..f3eb176b3 100644 --- a/include/proto.h +++ b/include/proto.h @@ -43,6 +43,9 @@ void sendto_serv_butone_token(aClient *one, char *prefix, char *command, char *t void sendto_serv_butone_token_opt(aClient *one, int opt, char *prefix, char *command, char *token, char *pattern, ...); void sendto_channel_ntadmins(aClient *from, aChannel *chptr, char *pattern, ...); +/* fdlist.c */ +EVENT(lcf_check); +EVENT(htm_calc); /* ircd.c */ EVENT(e_check_fdlists); EVENT(garbage_collect); diff --git a/src/events.c b/src/events.c index 00ebb08b4..d0976b586 100644 --- a/src/events.c +++ b/src/events.c @@ -161,7 +161,9 @@ void SetupEvents(void) EventAdd("tunefile", 300, 0, save_tunefile, NULL); EventAdd("garbage", GARBAGE_COLLECT_EVERY, 0, garbage_collect, NULL); EventAdd("loop", 0, 0, loop_event, NULL); -#ifndef NO_FDLISTS +#ifndef NO_FDLIST EventAdd("fdlistcheck", 1, 0, e_check_fdlists, NULL); + EventAdd("lcf", LCF, 0, lcf_check, NULL); + EventAdd("htmcalc", 1, 0, htm_calc, NULL); #endif } diff --git a/src/fdlist.c b/src/fdlist.c index ddcc6bbe4..2ec2169cf 100644 --- a/src/fdlist.c +++ b/src/fdlist.c @@ -84,3 +84,65 @@ void init_fdlist(fdlist * listp) memset((char *)listp->entry, '\0', sizeof(listp->entry)); return; } + +EVENT(lcf_check) +{ + static int lrv; + + lrv = LRV * LCF; + if ((me.receiveK - lrv >= lastrecvK) || HTMLOCK == 1) + { + if (!lifesux) + { + + lifesux = 1; + if (noisy_htm) + sendto_realops + ("Entering high-traffic mode (incoming = %0.2f kb/s (LRV = %dk/s, outgoing = %0.2f kb/s currently)", + currentrate, LRV, + currentrate2);} + else + { + lifesux++; /* Ok, life really sucks! */ + LCF += 2; /* wait even longer */ + EventModEvery("lcf", LCF); + if (noisy_htm) + sendto_realops + ("Still high-traffic mode %d%s (%d delay): %0.2f kb/s", + lifesux, + (lifesux > + 9) ? " (TURBO)" : + "", (int)LCF, currentrate); + /* Reset htm here, because its been on a little too long. + * Bad Things(tm) tend to happen with HTM on too long -epi */ + if (lifesux > 15) + { + if (noisy_htm) + sendto_realops + ("Resetting HTM and raising limit to: %dk/s\n", + LRV + 5); + LCF = LOADCFREQ; + EventModEvery("lcf", LCF); + lifesux = 0; + LRV += 5; + } + } + } + else + { + LCF = LOADCFREQ; + EventModEvery("lcf", LCF); + if (lifesux) + { + lifesux = 0; + if (noisy_htm) + sendto_realops + ("Resuming standard operation (incoming = %0.2f kb/s, outgoing = %0.2f kb/s now)", + currentrate, currentrate2); + } + } +} + +EVENT(htm_calc) +{ +} \ No newline at end of file diff --git a/src/ircd.c b/src/ircd.c index b40666182..6b5bfad76 100644 --- a/src/ircd.c +++ b/src/ircd.c @@ -125,6 +125,8 @@ TS LCF = LOADCFREQ; int currlife = 0; int HTMLOCK = 0; int noisy_htm = 1; +long lastrecvK = 0; +long lastsendK = 0; TS check_fdlists(); #endif @@ -1271,64 +1273,8 @@ void SocketLoop(void *dummy) #ifndef NO_FDLIST { - static long lastrecvK, lastsendK; - static int lrv; - if (timeofday - alllasttime < LCF) - goto done_check; - alllasttime = timeofday; - lrv = LRV * LCF; - if ((me.receiveK - lrv >= lastrecvK) || HTMLOCK == 1) - { - if (!lifesux) - { - - lifesux = 1; - if (noisy_htm) - sendto_realops - ("Entering high-traffic mode (incoming = %0.2f kb/s (LRV = %dk/s, outgoing = %0.2f kb/s currently)", - currentrate, LRV, - currentrate2);} - else - { - lifesux++; /* Ok, life really sucks! */ - LCF += 2; /* wait even longer */ - if (noisy_htm) - sendto_realops - ("Still high-traffic mode %d%s (%d delay): %0.2f kb/s", - lifesux, - (lifesux > - 9) ? " (TURBO)" : - "", (int)LCF, currentrate); - /* Reset htm here, because its been on a little too long. - * Bad Things(tm) tend to happen with HTM on too long -epi */ - if (lifesux > 15) - { - if (noisy_htm) - sendto_realops - ("Resetting HTM and raising limit to: %dk/s\n", - LRV + 5); - LCF = LOADCFREQ; - lifesux = 0; - LRV += 5; - } - - } - } - else - { - LCF = LOADCFREQ; - if (lifesux) - { - lifesux = 0; - if (noisy_htm) - sendto_realops - ("Resuming standard operation (incoming = %0.2f kb/s, outgoing = %0.2f kb/s now)", - currentrate, currentrate2); - } - } lastrecvK = me.receiveK; lastsendK = me.sendK; - done_check: if (alllasttime != timeofday) { currentrate = diff --git a/src/s_unreal.c b/src/s_unreal.c index 167ae9bca..fcec5ccf3 100644 --- a/src/s_unreal.c +++ b/src/s_unreal.c @@ -720,11 +720,13 @@ int m_htm(aClient *cptr, aClient *sptr, int parc, char *parv[]) parv[0], sptr->user->username, sptr->user->realhost); LCF = 60; /* 60 seconds */ + EventModEvery("lcf", LCF); } else if (!stricmp(command, "OFF")) { lifesux = 0; LCF = LOADCFREQ; + EventModEvery("lcf", LCF); sendto_one(sptr, ":%s NOTICE %s :High traffic mode is now OFF.", me.name, parv[0]);