aboutsummaryrefslogtreecommitdiffstats
path: root/servers-master.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--servers-master.c26
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++);