Slightly tweek communication protocol for -l option

This commit is contained in:
Marc André Tanner 2016-01-03 12:03:02 +01:00
parent 75dc9a52fa
commit 577ae6ae7a
3 changed files with 13 additions and 13 deletions

View File

@ -77,9 +77,6 @@ typedef struct {
char msg[BUFSIZ];
struct winsize ws;
int i;
struct {
bool ro, lp;
} attach;
} u;
} Packet;
@ -93,7 +90,10 @@ struct Client {
STATE_DISCONNECTED,
} state;
bool need_resize;
bool readonly;
enum {
CLIENT_READONLY = 1 << 0,
CLIENT_LOWPRIORITY = 1 << 1,
} flags;
Client *next;
};
@ -116,7 +116,7 @@ typedef struct {
static Server server = { .running = true, .exit_status = -1, .host = "@localhost" };
static Client client;
static struct termios orig_term, cur_term;
static bool has_term, alternate_buffer, low_priority;
static bool has_term, alternate_buffer;
static struct sockaddr_un sockaddr = {
.sun_family = AF_UNIX,
@ -603,10 +603,10 @@ int main(int argc, char *argv[]) {
force = true;
break;
case 'r':
client.readonly = true;
client.flags |= CLIENT_READONLY;
break;
case 'l':
low_priority = true;
client.flags |= CLIENT_LOWPRIORITY;
break;
case 'v':
puts("abduco-"VERSION" © 2013-2015 Marc André Tanner");

View File

@ -62,8 +62,8 @@ static int client_mainloop(void) {
client.need_resize = true;
Packet pkt = {
.type = MSG_ATTACH,
.u = { .attach = { .ro = client.readonly, .lp = low_priority } },
.len = sizeof(pkt.u.attach),
.u.i = client.flags,
.len = sizeof(pkt.u.i),
};
client_send_packet(&pkt);
@ -126,7 +126,7 @@ static int client_mainloop(void) {
client_send_packet(&pkt);
close(server.socket);
return -1;
} else if (!client.readonly) {
} else if (!(client.flags & CLIENT_READONLY)) {
client_send_packet(&pkt);
}
}

View File

@ -213,14 +213,14 @@ static void server_mainloop(void) {
server_write_pty(&client_packet);
break;
case MSG_ATTACH:
c->readonly = client_packet.u.attach.ro;
if (client_packet.u.attach.lp)
c->flags = client_packet.u.i;
if (c->flags & CLIENT_LOWPRIORITY)
server_sink_client();
break;
case MSG_RESIZE:
c->state = STATE_ATTACHED;
case MSG_REDRAW:
if (!c->readonly && (client_packet.type == MSG_REDRAW || c == server.clients)) {
if (!(c->flags & CLIENT_READONLY) && (client_packet.type == MSG_REDRAW || c == server.clients)) {
debug("server-ioct: TIOCSWINSZ\n");
ioctl(server.pty, TIOCSWINSZ, &client_packet.u.ws);
}