summary refs log tree commit diff
path: root/bounce.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-05-11 16:36:31 -0400
committerJune McEnroe <june@causal.agency>2020-05-11 16:36:31 -0400
commite6ca38288f38707fda5f29f5308d089a54551110 (patch)
tree7c09a5dba301879ce21f44aca0158a77ddd3ea97 /bounce.c
parentUse . as ${LDLIBS.$@} separator (diff)
downloadpounce-e6ca38288f38707fda5f29f5308d089a54551110.tar.gz
pounce-e6ca38288f38707fda5f29f5308d089a54551110.zip
Check signals after handling ready sockets
In the case where a signal arrives while handling a ready socket, it
should be handled as soon as possible, rather than waiting for poll to
return again. Signals will still be handled immediately if poll returns
-1 due to EINTR.
Diffstat (limited to '')
-rw-r--r--bounce.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/bounce.c b/bounce.c
index 1aae7a3..21355ea 100644
--- a/bounce.c
+++ b/bounce.c
@@ -458,26 +458,19 @@ int main(int argc, char *argv[]) {
 	eventAdd(server, NULL);
 
 	for (;;) {
-		int nfds = poll(event.fds, event.len, -1);
-		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
-		if (signals[SIGINT] || signals[SIGTERM]) break;
-
-		if (signals[SIGINFO]) {
-			ringInfo();
-			signals[SIGINFO] = 0;
+		for (size_t i = binds + 1; i < event.len; ++i) {
+			assert(event.clients[i]);
+			if (clientDiff(event.clients[i])) {
+				event.fds[i].events |= POLLOUT;
+			} else {
+				event.fds[i].events &= ~POLLOUT;
+			}
 		}
 
-		if (signals[SIGUSR1]) {
-			cert = splitOpen(certSplit);
-			priv = splitOpen(privSplit);
-			localConfig(cert, priv, localCA, !clientPass);
-			fclose(cert);
-			fclose(priv);
-			signals[SIGUSR1] = 0;
-		}
+		int nfds = poll(event.fds, event.len, -1);
+		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
 
-		if (nfds < 0) continue;
-		for (size_t i = event.len - 1; i < event.len; --i) {
+		for (size_t i = event.len - 1; nfds > 0 && i < event.len; --i) {
 			short revents = event.fds[i].revents;
 			if (!revents) continue;
 
@@ -514,13 +507,20 @@ int main(int argc, char *argv[]) {
 			}
 		}
 
-		for (size_t i = binds + 1; i < event.len; ++i) {
-			assert(event.clients[i]);
-			if (clientDiff(event.clients[i])) {
-				event.fds[i].events |= POLLOUT;
-			} else {
-				event.fds[i].events &= ~POLLOUT;
-			}
+		if (signals[SIGINT] || signals[SIGTERM]) break;
+
+		if (signals[SIGINFO]) {
+			ringInfo();
+			signals[SIGINFO] = 0;
+		}
+
+		if (signals[SIGUSR1]) {
+			cert = splitOpen(certSplit);
+			priv = splitOpen(privSplit);
+			localConfig(cert, priv, localCA, !clientPass);
+			fclose(cert);
+			fclose(priv);
+			signals[SIGUSR1] = 0;
 		}
 	}
 
> 2019-02-23Call def_prog_mode after termNoFlowJune McEnroe So that the settings get restored after /url or /man. 2019-02-22Move IRC formatting reset to C-sJune McEnroe Opens C-n for window switching. 2019-02-22Disable terminal flow controlJune McEnroe This opens up C-o, C-q and C-s for key bindings without C-v. 2019-02-22Bind up and down arrows to scrollJune McEnroe Honestly it's kind of weird that IRC clients usually use these for input history. 2019-02-22Remove topic TODOJune McEnroe I played around with it and it doesn't look right unless there is only one channel listed in the status. 2019-02-22Add /znc commandJune McEnroe Only because ZNC tells you to use it and expects it to work. 2019-02-22Update status line after scrolling and term eventsJune McEnroe 2019-02-22Reorganize input.cJune McEnroe 2019-02-22Fix name of <raw> window in man pageJune McEnroe 2019-02-22Rename global tags with angle bracketsJune McEnroe 2019-02-22Show status window while connectingJune McEnroe 2019-02-22Reorganize UI code for the umpteenth timeJune McEnroe It's actually in a good state now, I think. 2019-02-21Replace "view" with "window"June McEnroe I think originally I didn't want to use the same word as curses WINDOW but it's really much clearer for the user if they're just called windows. UI code probably needs yet another rewrite though. Still feels messy. 2019-02-21Remove ROT13June McEnroe It's just not convenient when it can only do the whole line... 2019-02-21Clean up man pageJune McEnroe 2019-01-26Draw UI before connectingJune McEnroe Otherwise the "Traveling" message isn't visible while connecting. 2019-01-25Avoid unused variable warnings with getyxJune McEnroe 2019-01-25Add GNU/Linux build instructionsJune McEnroe