diff options
| author | Mattias Andrée <m@maandree.se> | 2026-11-20 16:56:47 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-11-20 16:56:47 +0100 |
| commit | cf3b92233edaa90a504b07625972ea746271e9bb (patch) | |
| tree | 4ef72b60b18266de799bc8394a91f2ed0b84293b /servers-master.c | |
| parent | fix doc text (diff) | |
| download | coopgammad-cf3b92233edaa90a504b07625972ea746271e9bb.tar.gz coopgammad-cf3b92233edaa90a504b07625972ea746271e9bb.tar.bz2 coopgammad-cf3b92233edaa90a504b07625972ea746271e9bb.tar.xz | |
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to 'servers-master.c')
| -rw-r--r-- | servers-master.c | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/servers-master.c b/servers-master.c index f6ebfee..9b01c00 100644 --- a/servers-master.c +++ b/servers-master.c @@ -105,8 +105,8 @@ dispatch_message(size_t conn, struct message *restrict msg) * the server socket and all connections * * The file descriptor will be ordered as in - * the array `connections`, `socketfd` will - * be last. + * the array `connections`, followed by `socketfd` + * and the display-server file descriptor if available. * * @param fds Reference parameter for the array of file descriptors * @param fdn Output parameter for the number of file descriptors @@ -120,12 +120,12 @@ update_fdset(struct pollfd **restrict fds, nfds_t *restrict fdn, nfds_t *restric nfds_t j = 0; void *new; - if (connections_used + 1 > *fds_alloc) { - new = realloc(*fds, (connections_used + 1) * sizeof(**fds)); + if (connections_used + 1 + (displayfd >= 0) > *fds_alloc) { + new = realloc(*fds, (connections_used + 1 + (displayfd >= 0)) * sizeof(**fds)); if (!new) return -1; *fds = new; - *fds_alloc = connections_used + 1; + *fds_alloc = connections_used + 1 + (displayfd >= 0); } for (i = 0; i < connections_used; i++) { @@ -140,6 +140,12 @@ update_fdset(struct pollfd **restrict fds, nfds_t *restrict fdn, nfds_t *restric (*fds)[j].events = NON_WR_POLL_EVENTS; j++; + if (displayfd >= 0) { + (*fds)[j].fd = displayfd; + (*fds)[j].events = 0; + j++; + } + *fdn = j; return 0; } @@ -316,6 +322,8 @@ main_loop(void) goto fail; } connection = 0; + if (update_fdset(&fds, &fdn, &fds_alloc) < 0) + goto fail; } for (j = 0, i = 0; j < connections_used; j++) { @@ -328,6 +336,8 @@ main_loop(void) } } fds[i].revents = 0; + if (displayfd >= 0) + fds[fdn - 1].revents = 0; if (poll(fds, fdn, -1) < 0) { if (errno == EAGAIN) @@ -344,7 +354,11 @@ main_loop(void) if (!do_read && !do_write) continue; - if (fd == socketfd) { + if (fd == displayfd) { + if (connection != 1) + terminate = 1; + continue; + } else if (fd == socketfd) { r = handle_server(); } else { for (j = 0; connections[j] != fd; j++); |
