diff options
author | June McEnroe <june@causal.agency> | 2018-03-05 12:58:18 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2018-03-05 12:58:18 -0500 |
commit | 9387958f8a6bae28f4c9b115aef12e8163393aec (patch) | |
tree | 60c1b7a8cb4f9b0a44df3eabd917ea4676beaa17 /help.c | |
parent | Use stdio in merge and meta (diff) | |
download | torus-9387958f8a6bae28f4c9b115aef12e8163393aec.tar.gz torus-9387958f8a6bae28f4c9b115aef12e8163393aec.zip |
Pass message structs by value
Diffstat (limited to '')
-rw-r--r-- | help.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/help.c b/help.c index 7fa7e9b..4415065 100644 --- a/help.c +++ b/help.c @@ -25,9 +25,9 @@ static int client; -static void clientMessage(const struct ClientMessage *msg) { - ssize_t len = send(client, msg, sizeof(*msg), 0); - if (len < 0) err(EX_IOERR, "send"); +static void clientMessage(struct ClientMessage msg) { + ssize_t size = send(client, &msg, sizeof(msg), 0); + if (size < 0) err(EX_IOERR, "send"); } static void clientMove(int8_t dx, int8_t dy) { @@ -35,7 +35,7 @@ static void clientMove(int8_t dx, int8_t dy) { .type = CLIENT_MOVE, .data.m = { .dx = dx, .dy = dy }, }; - clientMessage(&msg); + clientMessage(msg); } static void clientPut(uint8_t color, char cell) { @@ -43,7 +43,7 @@ static void clientPut(uint8_t color, char cell) { .type = CLIENT_PUT, .data.p = { .color = color, .cell = cell }, }; - clientMessage(&msg); + clientMessage(msg); } #define DELAY (50000) @@ -96,7 +96,7 @@ int main() { .sun_path = "torus.sock", }; int error = connect(client, (struct sockaddr *)&addr, sizeof(addr)); - if (error) err(EX_IOERR, "torus.sock"); + if (error) err(EX_NOINPUT, "torus.sock"); pid_t pid = fork(); if (pid < 0) err(EX_OSERR, "fork"); @@ -104,9 +104,9 @@ int main() { if (!pid) { for (;;) { char buf[4096]; - ssize_t len = recv(client, buf, sizeof(buf), 0); - if (len < 0) err(EX_IOERR, "recv"); - if (!len) return EX_OK; + ssize_t size = recv(client, buf, sizeof(buf), 0); + if (size < 0) err(EX_IOERR, "recv"); + if (!size) return EX_OK; } } |