mirror of
https://github.com/tmate-io/tmate.git
synced 2025-08-16 16:41:35 +02:00
Clean up pause/exit mess with flags.
This commit is contained in:
46
client-msg.c
46
client-msg.c
@ -1,4 +1,4 @@
|
||||
/* $Id: client-msg.c,v 1.7 2007-10-04 11:52:02 nicm Exp $ */
|
||||
/* $Id: client-msg.c,v 1.8 2007-10-05 14:23:28 nicm Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -51,27 +51,24 @@ client_msg_dispatch(struct client_ctx *cctx, char **error)
|
||||
struct hdr hdr;
|
||||
struct client_msg *msg;
|
||||
u_int i;
|
||||
int n;
|
||||
|
||||
for (;;) {
|
||||
if (BUFFER_USED(cctx->srv_in) < sizeof hdr)
|
||||
if (BUFFER_USED(cctx->srv_in) < sizeof hdr)
|
||||
return (1);
|
||||
memcpy(&hdr, BUFFER_OUT(cctx->srv_in), sizeof hdr);
|
||||
if (BUFFER_USED(cctx->srv_in) < (sizeof hdr) + hdr.size)
|
||||
return (1);
|
||||
buffer_remove(cctx->srv_in, sizeof hdr);
|
||||
|
||||
for (i = 0; i < NCLIENTMSG; i++) {
|
||||
msg = client_msg_table + i;
|
||||
if (msg->type == hdr.type) {
|
||||
if (msg->fn(&hdr, cctx, error) != 0)
|
||||
return (-1);
|
||||
return (0);
|
||||
memcpy(&hdr, BUFFER_OUT(cctx->srv_in), sizeof hdr);
|
||||
if (BUFFER_USED(cctx->srv_in) < (sizeof hdr) + hdr.size)
|
||||
return (0);
|
||||
buffer_remove(cctx->srv_in, sizeof hdr);
|
||||
|
||||
for (i = 0; i < NCLIENTMSG; i++) {
|
||||
msg = client_msg_table + i;
|
||||
if (msg->type == hdr.type) {
|
||||
if ((n = msg->fn(&hdr, cctx, error)) != 0)
|
||||
return (n);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == NCLIENTMSG)
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
if (i == NCLIENTMSG)
|
||||
fatalx("unexpected message");
|
||||
}
|
||||
|
||||
int
|
||||
@ -88,7 +85,10 @@ client_msg_fn_pause(
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_PAUSE size");
|
||||
return (1);
|
||||
|
||||
cctx->flags |= CCTX_PAUSE;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
@ -106,24 +106,24 @@ client_msg_fn_error(struct hdr *hdr, struct client_ctx *cctx, char **error)
|
||||
|
||||
int
|
||||
client_msg_fn_exit(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, char **error)
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_EXIT size");
|
||||
|
||||
*error = xstrdup("");
|
||||
cctx->flags |= CCTX_EXIT;
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
int
|
||||
client_msg_fn_detach(
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, char **error)
|
||||
struct hdr *hdr, unused struct client_ctx *cctx, unused char **error)
|
||||
{
|
||||
if (hdr->size != 0)
|
||||
fatalx("bad MSG_DETACH size");
|
||||
|
||||
*error = NULL;
|
||||
cctx->flags |= CCTX_DETACH;
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user