ticl

tiny irc channel linker
git clone git://git.ircforever.org/ticl
Log | Files | Refs | Submodules | README | LICENSE

commit 889af18831aba0673a2456f05a1987b972d22df6
parent abeb6b0542e9b7db6ce1ab102f03fc7499f54eb2
Author: libredev <libredev@ircforever.org>
Date:   Wed, 23 Nov 2022 18:22:18 +0530

added delay between connections

Diffstat:
MMakefile | 7++++++-
Mmain.c | 37++++++++++++++++++++++++++++++-------
2 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile @@ -19,8 +19,13 @@ OBJECTS = $(SOURCES:.c=.o) all: clean libpicoev.a $(PROGRAM) +all: clean libpicoev.a $(PROGRAM) + +libpicoev.a: + cd picoev && $(MAKE) libpicoev.a LINUX_BUILD=1 CC_DEBUG_FLAGS=-g + libpicoev.a: - cd picoev && $(MAKE) libpicoev.a CC=gcc LINUX_BUILD=1 CC_DEBUG_FLAGS=-g + cd picoev && $(MAKE) libpicoev.a LINUX_BUILD=1 CC_DEBUG_FLAGS=-g $(PROGRAM): $(OBJECTS) $(CC) -o $@ $(OBJECTS) $(LDFLAGS) diff --git a/main.c b/main.c @@ -23,6 +23,8 @@ #define NET_ADDEND 10 #define USER_ADDEND 100 #define EVENT_TIMEOUT 10000 +#define FIFO_TIMEOUT 5 +#define EVENT_FREQUENCY 5 #define UNUSED(x) (void)(x) @@ -113,7 +115,7 @@ main(int argc, char *argv[]) /* get fifo fd */ fd = fifo_open(argv[1]); /* add fifo fd */ - picoev_add(loop, fd, PICOEV_READ, 0, fifo_event_cb, argv[1]); + picoev_add(loop, fd, PICOEV_READ, FIFO_TIMEOUT, fifo_event_cb, argv[1]); /* loop */ while (!done) picoev_loop_once(loop, 10); @@ -131,7 +133,28 @@ fifo_event_cb(picoev_loop *loop, int fd, int revents, void *cb_arg) char *cmd; ssize_t n; - UNUSED(revents); + int i, count = 0; + Htiter it = {0}; + + if ((revents & PICOEV_TIMEOUT) != 0) { + printf("TIME to add %d more connections\n", EVENT_FREQUENCY); + while (htiterate(users, &it)) { + for (i = 0; i < netlen; i++) { + if (((int *)it.node->val)[i] == 0) { + ((int *)it.node->val)[i] = clone_add(loop, it.node->key, i); + count++; + if (count >= 10) + goto return_time; + } + } + } +return_time: + picoev_del(loop, fd); + close(fd); + fd = fifo_open((char *)cb_arg); + picoev_add(loop, fd, PICOEV_READ, FIFO_TIMEOUT, fifo_event_cb, cb_arg); + return; + } n = readline(fd, buffer, sizeof(buffer)); if (n == -1) { @@ -143,7 +166,7 @@ fifo_event_cb(picoev_loop *loop, int fd, int revents, void *cb_arg) picoev_del(loop, fd); close(fd); fd = fifo_open((char *)cb_arg); - picoev_add(loop, fd, PICOEV_READ, 0, fifo_event_cb, cb_arg); + picoev_add(loop, fd, PICOEV_READ, FIFO_TIMEOUT, fifo_event_cb, cb_arg); return; } @@ -213,10 +236,10 @@ server_event_cb(picoev_loop *loop, int fd, int revents, void *cb_arg) if (errno == EAGAIN || errno == EWOULDBLOCK) return; printf("error: read: %d: %s\n", fd, strerror(errno)); - clean_exit(loop, 1); + event_del(loop, id); } else if (n == 0) { /* reopen fifo again */ printf("error: closed: %d\n", fd); - clean_exit(loop, 1); + event_del(loop, id); } /* remove CRLFs */ @@ -359,7 +382,7 @@ server_event_cb(picoev_loop *loop, int fd, int revents, void *cb_arg) char *nick; split(&buf, ':'); networks[netid].join = 1; - net_update(loop, netid); + /* net_update(loop, netid); */ while (*(nick = split(&buf, ' ')) != '\0') { if (*nick == '@' || *nick == '&' @@ -614,7 +637,7 @@ user_add(picoev_loop *loop, char *unick, int netid) if (i == netid) { ids[i] = -1; } else { - ids[i] = clone_add(loop, nick, i); + /* ids[i] = clone_add(loop, nick, i); */ } } /* insert it to the users hash table */