mirror of https://github.com/omar-polo/gmid.git
server: inline dispatch_imsg
This commit is contained in:
parent
24232204eb
commit
d040746a37
67
server.c
67
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;
|
||||
|
@ -1317,30 +1312,50 @@ client_by_id(int id)
|
|||
return SPLAY_FIND(client_tree_id, &clients, &find);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_imsg_quit(struct imsgbuf *ibuf, struct imsg *imsg, size_t len)
|
||||
{
|
||||
/*
|
||||
* don't call event_loopbreak since we want to finish to
|
||||
* handle 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);
|
||||
}
|
||||
|
||||
static void
|
||||
handle_dispatch_imsg(int fd, short ev, void *d)
|
||||
{
|
||||
struct imsgbuf *ibuf = d;
|
||||
dispatch_imsg(ibuf, handlers, sizeof(handlers));
|
||||
struct imsgbuf *ibuf = d;
|
||||
struct imsg imsg;
|
||||
ssize_t n;
|
||||
|
||||
if ((n = imsg_read(ibuf)) == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK)
|
||||
return;
|
||||
fatal("imsg_read");
|
||||
}
|
||||
|
||||
if (n == 0)
|
||||
fatal("connection closed."); /* XXX: fatalx */
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue