diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-21 21:44:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-21 21:44:04 +0000 |
commit | a7aed6642cfa6944942ee8de498f58bdab9320a7 (patch) | |
tree | 4b1030171f62022448496b5439479ea7d0c482aa | |
parent | d79e4c8d8a55b9453bb9376efb67b20c8779fff4 (diff) |
-handle partial writes and IO errors, even on stdout
-rw-r--r-- | src/mesh/gnunet-mesh.c | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c index b60a8c0e49..8a568cb53e 100644 --- a/src/mesh/gnunet-mesh.c +++ b/src/mesh/gnunet-mesh.c @@ -330,11 +330,27 @@ data_callback (void *cls, const struct GNUNET_MessageHeader *message) { uint16_t len; + ssize_t done; + uint16_t off; + const char *buf; GNUNET_break (ch == channel); len = ntohs (message->size) - sizeof (*message); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); - write (1, (char *) &message[1], len); + buf = (const char *) &message[1]; + off = 0; + while (off < len) + { + done = write (1, &buf[off], len - off); + if (done <= 0) + { + if (-1 == done) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, + "write"); + return GNUNET_SYSERR; + } + off += done; + } return GNUNET_OK; } |