converted htmcalc/lcf to events

This commit is contained in:
stskeeps 2001-05-15 12:02:39 +00:00
parent 746f5b8420
commit 2da8a5fd52
8 changed files with 101 additions and 60 deletions

View file

@ -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

View file

@ -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);

View file

@ -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
*/

View file

@ -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);

View file

@ -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
}

View file

@ -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)
{
}

View file

@ -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 =

View file

@ -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]);