Added two-stroke mechanism for detaching

This commit is contained in:
Michael Krayer 2023-10-11 10:50:16 +02:00
parent 3c5aafc0fb
commit c80e8ff369
2 changed files with 13 additions and 5 deletions

View File

@ -63,6 +63,7 @@ static int client_mainloop(void) {
sigprocmask(SIG_BLOCK, &blockset, NULL); sigprocmask(SIG_BLOCK, &blockset, NULL);
client.need_resize = true; client.need_resize = true;
client.await_command = false;
Packet pkt = { Packet pkt = {
.type = MSG_ATTACH, .type = MSG_ATTACH,
.u.i = client.flags, .u.i = client.flags,
@ -121,15 +122,21 @@ static int client_mainloop(void) {
die("client-stdin"); die("client-stdin");
if (len > 0) { if (len > 0) {
debug("client-stdin: %c\n", pkt.u.msg[0]); debug("client-stdin: %c\n", pkt.u.msg[0]);
if (client.await_command) {
client.await_command = false;
if (pkt.u.msg[0]=='d') {
pkt.type = MSG_DETACH;
pkt.len = 0;
client_send_packet(&pkt);
close(server.socket);
return -1;
}
}
pkt.len = len; pkt.len = len;
if (KEY_REDRAW && pkt.u.msg[0] == KEY_REDRAW) { if (KEY_REDRAW && pkt.u.msg[0] == KEY_REDRAW) {
client.need_resize = true; client.need_resize = true;
} else if (pkt.u.msg[0] == KEY_DETACH) { } else if (pkt.u.msg[0] == KEY_DETACH) {
pkt.type = MSG_DETACH; client.await_command = true;
pkt.len = 0;
client_send_packet(&pkt);
close(server.socket);
return -1;
} else if (!(client.flags & CLIENT_READONLY)) { } else if (!(client.flags & CLIENT_READONLY)) {
client_send_packet(&pkt); client_send_packet(&pkt);
} }

View File

@ -100,6 +100,7 @@ struct Client {
CLIENT_LOWPRIORITY = 1 << 1, CLIENT_LOWPRIORITY = 1 << 1,
} flags; } flags;
Client *next; Client *next;
bool await_command;
}; };
typedef struct { typedef struct {