abduco

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit fdf943d520fc7c0e4d77f83a169941a76b14083e
parent a7e13911c568450e6a3c62d54c65a091fc441cc4
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 18 Jun 2014 11:35:26 +0200

Make sure that clients are informed about session termination

Diffstat:
server.c | 33++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/server.c b/server.c @@ -152,11 +152,12 @@ static void server_mainloop() { FD_ZERO(&new_writefds); FD_SET(server.socket, &new_readfds); int new_fdmax = server.socket; + bool exit_packet_delivered = false; + if (server.read_pty) FD_SET_MAX(server.pty, &new_readfds, new_fdmax); - Packet *exit_pkt = NULL; - while (!exit_pkt) { + while (server.clients || !exit_packet_delivered) { int fdmax = new_fdmax; fd_set readfds = new_readfds; fd_set writefds = new_writefds; @@ -182,16 +183,6 @@ static void server_mainloop() { if (FD_ISSET(server.pty, &readfds)) pty_data = server_read_pty(&server_packet); - if (!server.running && server.exit_status != -1 && server.clients) { /* application terminated */ - Packet pkt = { - .type = MSG_EXIT, - .u.i = server.exit_status, - .len = sizeof(pkt.u.i), - }; - exit_pkt = &pkt; - server.exit_status = -1; - } - for (Client **prev_next = &server.clients, *c = server.clients; c;) { if (c->state == STATE_DISCONNECTED) { bool first = (c == server.clients); @@ -239,9 +230,21 @@ static void server_mainloop() { if (pty_data) server_send_packet(c, &server_packet); - if (exit_pkt) - server_send_packet(c, exit_pkt); - + if (!server.running) { + if (server.exit_status != -1) { + Packet pkt = { + .type = MSG_EXIT, + .u.i = server.exit_status, + .len = sizeof(pkt.u.i), + }; + if (server_send_packet(c, &pkt)) + exit_packet_delivered = true; + else + FD_SET_MAX(c->socket, &new_writefds, new_fdmax); + } else { + FD_SET_MAX(c->socket, &new_writefds, new_fdmax); + } + } prev_next = &c->next; c = c->next; }