From 548c4a3a86a37cf74aac5ef91f84b9a762dc1023 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 11 May 2020 18:05:41 -0400 Subject: Add server send queueing with time interval This addresses pounce getting killed with "Excess flood" when it sends NAMES commands for too many channels when a client connects. These commands, as well as automatic AWAY commands, are by default throttled to 5 per second. Tested on freenode with 36 channels and 200ms interval. --- server.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'server.c') diff --git a/server.c b/server.c index 20d94e3..1edeab5 100644 --- a/server.c +++ b/server.c @@ -148,6 +148,46 @@ void serverFormat(const char *format, ...) { serverSend(buf, len); } +enum { QueueCap = 256 }; +static struct { + size_t enq; + size_t deq; + char *msgs[QueueCap]; +} queue; + +void serverDequeue(void) { + if (queue.enq - queue.deq) { + char *msg = queue.msgs[queue.deq++ % QueueCap]; + serverSend(msg, strlen(msg)); + free(msg); + } else { + struct itimerval timer = { .it_value = {0} }; + int error = setitimer(ITIMER_REAL, &timer, NULL); + if (error) err(EX_OSERR, "setitimer"); + } +} + +struct timeval serverQueueInterval = { .tv_usec = 1000 * 200 }; + +void serverEnqueue(const char *format, ...) { + if (queue.enq - queue.deq == QueueCap) { + warnx("server send queue full"); + serverDequeue(); + } else if (queue.enq == queue.deq) { + struct itimerval timer = { + .it_interval = serverQueueInterval, + .it_value = { .tv_usec = 1 }, + }; + int error = setitimer(ITIMER_REAL, &timer, NULL); + if (error) err(EX_OSERR, "setitimer"); + } + va_list ap; + va_start(ap, format); + int len = vasprintf(&queue.msgs[queue.enq++ % QueueCap], format, ap); + va_end(ap); + if (len < 0) err(EX_OSERR, "vasprintf"); +} + void serverRecv(void) { static char buf[MessageCap]; static size_t len; -- cgit 1.4.1 t' value='search'/>
path: root/doc/zlib/inflateBackInit.3 (unfollow)
Commit message (Expand)Author
2022-07-26Add -w to upJune McEnroe
2022-07-13Set push.autoSetupRemoteJune McEnroe
2022-07-08Remove TOURJune McEnroe
2022-07-03Add The Bone Shard EmperorJune McEnroe
2022-06-25Bump xterm font size to 12June McEnroe
2022-06-10Handle subshells (and functions) inside substitutionsJune McEnroe
2022-06-10Switch to jorts Install scriptJune McEnroe
2022-06-08Indicate if still reading or no resultsJune McEnroe
2022-06-08Add Maiden, Mother, CroneJune McEnroe
2022-06-05FIRST SHOW IN 2.5 YEARS BABEY!!!June McEnroe
2022-06-03Set line number on File linesJune McEnroe
2022-06-03Stop polling stdin after EOFJune McEnroe
2022-06-02Set TABSIZE=4June McEnroe
2022-06-02Do basic match highlightingJune McEnroe
2022-06-02Clean up parsing a littleJune McEnroe
2022-06-02Don't duplicate path stringJune McEnroe
2022-06-02Use stderr instead of /dev/tty, realloc buffer if lines too longJune McEnroe
2022-06-02Add initial working version of qfJune McEnroe
2022-05-29Set prompt for okshJune McEnroe