aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgretchen <gretchen@gnar.cool>2019-11-17 22:42:03 -0800
committergretchen <gretchen@gnar.cool>2019-11-17 22:42:03 -0800
commita280edac7a0a2be59e128920ab58e265452aa864 (patch)
tree21a7c8dc1bed726462824a080c2b267d251427af
parente03849c6c7c0b224c78612186e31032edb3b6231 (diff)
downloadnorns-etc-a280edac7a0a2be59e128920ab58e265452aa864.tar.gz
norns-etc-a280edac7a0a2be59e128920ab58e265452aa864.zip
wait for one message after EOF
-rw-r--r--norns_shell.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/norns_shell.c b/norns_shell.c
index fc7867d..10f10b0 100644
--- a/norns_shell.c
+++ b/norns_shell.c
@@ -89,7 +89,9 @@ int main (int argc, char **argv)
int received = 0;
struct timespec sent_sentinel = {0};
- /* TODO wait for responses before exiting after EOF */
+ /* we'll also wait for one message after EOF... */
+ int sent_last = 0;
+
struct nn_pollfd poll_s = { .fd = s, .events = NN_POLLIN | NN_POLLOUT };
while (!killed) {
switch (nn_poll(&poll_s, 1, 1000)) {
@@ -120,6 +122,8 @@ int main (int argc, char **argv)
fprintf(stderr, "Couldn't write: %m\n");
goto error;
}
+ if (sent_last)
+ goto finish;
}
nn_freemsg(buf);
received = 1;
@@ -155,7 +159,7 @@ int main (int argc, char **argv)
goto error;
}
}
- if (n == 0) goto finish;
+ if (n == 0) sent_last = 1;
/* treat EAGAIN as "read 0" */
if (n < 1) n = 0;
line_n += n;