aboutsummaryrefslogtreecommitdiff
path: root/server.c
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2022-09-10 13:18:24 +0000
committerOmar Polo <op@omarpolo.com>2022-09-10 13:18:24 +0000
commitd040746a37a2af87b1b4ffe746e2f3b9231576f1 (patch)
tree32bb083d6a107168c0f9e7afe6640422fd42c72a /server.c
parent24232204eb43c6b12bdf7dfad526276bd914fadf (diff)
server: inline dispatch_imsg
Diffstat (limited to 'server.c')
-rw-r--r--server.c63
1 files changed, 39 insertions, 24 deletions
diff --git a/server.c b/server.c
index f9e9dbe..ebac30e 100644
--- a/server.c
+++ b/server.c
@@ -65,14 +65,9 @@ static void client_close_ev(int, short, void *);
static void do_accept(int, short, void*);
-static void handle_imsg_quit(struct imsgbuf*, struct imsg*, size_t);
static void handle_dispatch_imsg(int, short, void *);
static void handle_siginfo(int, short, void*);
-static imsg_handlerfn *handlers[] = {
- [IMSG_QUIT] = handle_imsg_quit,
-};
-
static uint32_t server_client_id;
struct client_tree_id clients;
@@ -1318,29 +1313,49 @@ client_by_id(int id)
}
static void
-handle_imsg_quit(struct imsgbuf *ibuf, struct imsg *imsg, size_t len)
+handle_dispatch_imsg(int fd, short ev, void *d)
{
- /*
- * don't call event_loopbreak since we want to finish to
- * handle the ongoing connections.
- */
+ struct imsgbuf *ibuf = d;
+ struct imsg imsg;
+ ssize_t n;
- shutting_down = 1;
+ if ((n = imsg_read(ibuf)) == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK)
+ return;
+ fatal("imsg_read");
+ }
- event_del(&e4);
- if (has_ipv6)
- event_del(&e6);
- if (has_siginfo)
- signal_del(&siginfo);
- event_del(&imsgev);
- signal_del(&sigusr2);
-}
+ if (n == 0)
+ fatal("connection closed."); /* XXX: fatalx */
-static void
-handle_dispatch_imsg(int fd, short ev, void *d)
-{
- struct imsgbuf *ibuf = d;
- dispatch_imsg(ibuf, handlers, sizeof(handlers));
+ for (;;) {
+ if ((n = imsg_get(ibuf, &imsg)) == -1)
+ fatal("imsg_get");
+ if (n == 0)
+ return;
+
+ switch (imsg.hdr.type) {
+ case IMSG_QUIT:
+ /*
+ * Don't call event_loopbreak since we want to
+ * finish handling the ongoing connections.
+ */
+ shutting_down = 1;
+
+ event_del(&e4);
+ if (has_ipv6)
+ event_del(&e6);
+ if (has_siginfo)
+ signal_del(&siginfo);
+ event_del(&imsgev);
+ signal_del(&sigusr2);
+ break;
+ default:
+ /* XXX: fatalx */
+ fatal("Unknown message %d", imsg.hdr.type);
+ }
+ imsg_free(&imsg);
+ }
}
static void