summaryrefslogtreecommitdiffstats
path: root/client-msg.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2007-10-05 14:23:28 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2007-10-05 14:23:28 +0000
commit91e24af08997ee5348366b3de5ab5167bf712a43 (patch)
tree0eb889d63f7039dee09aee09af51fc20005e196b /client-msg.c
parentfa65aec2ef256d6e8c2f64a39b213c57d48422f3 (diff)
Clean up pause/exit mess with flags.
Diffstat (limited to 'client-msg.c')
-rw-r--r--client-msg.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/client-msg.c b/client-msg.c
index bea15246..7942d994 100644
--- a/client-msg.c
+++ b/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)
- return (0);
- memcpy(&hdr, BUFFER_OUT(cctx->srv_in), sizeof hdr);
- if (BUFFER_USED(cctx->srv_in) < (sizeof hdr) + hdr.size)
+ 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);
- 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);
}