wm: ticl

Download patch

ref: 889af18831aba0673a2456f05a1987b972d22df6
parent: abeb6b0542e9b7db6ce1ab102f03fc7499f54eb2
author: libredev <libredev@ircforever.org>
date: Wed Nov 23 13:22:18 EST 2022

added delay between connections

--- a/Makefile
+++ b/Makefile
@@ -19,8 +19,13 @@
 
 all: clean libpicoev.a $(PROGRAM)
 
+all: clean libpicoev.a $(PROGRAM)
+
 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
+
+libpicoev.a:
+	cd picoev && $(MAKE) libpicoev.a LINUX_BUILD=1 CC_DEBUG_FLAGS=-g
 
 $(PROGRAM): $(OBJECTS)
 	$(CC) -o $@ $(OBJECTS) $(LDFLAGS)
--- 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 @@
 	/* 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,8 +133,29 @@
 	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) {
 		if (errno == EAGAIN || errno == EWOULDBLOCK)
@@ -143,7 +166,7 @@
 		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 @@
 		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 @@
 		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 @@
 		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 */