aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-21 21:44:04 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-21 21:44:04 +0000
commita7aed6642cfa6944942ee8de498f58bdab9320a7 (patch)
tree4b1030171f62022448496b5439479ea7d0c482aa /src
parentd79e4c8d8a55b9453bb9376efb67b20c8779fff4 (diff)
downloadgnunet-a7aed6642cfa6944942ee8de498f58bdab9320a7.tar.gz
gnunet-a7aed6642cfa6944942ee8de498f58bdab9320a7.zip
-handle partial writes and IO errors, even on stdout
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-mesh.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/mesh/gnunet-mesh.c b/src/mesh/gnunet-mesh.c
index b60a8c0e4..8a568cb53 100644
--- a/src/mesh/gnunet-mesh.c
+++ b/src/mesh/gnunet-mesh.c
@@ -330,11 +330,27 @@ data_callback (void *cls,
330 const struct GNUNET_MessageHeader *message) 330 const struct GNUNET_MessageHeader *message)
331{ 331{
332 uint16_t len; 332 uint16_t len;
333 ssize_t done;
334 uint16_t off;
335 const char *buf;
333 GNUNET_break (ch == channel); 336 GNUNET_break (ch == channel);
334 337
335 len = ntohs (message->size) - sizeof (*message); 338 len = ntohs (message->size) - sizeof (*message);
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len); 339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %u bytes\n", len);
337 write (1, (char *) &message[1], len); 340 buf = (const char *) &message[1];
341 off = 0;
342 while (off < len)
343 {
344 done = write (1, &buf[off], len - off);
345 if (done <= 0)
346 {
347 if (-1 == done)
348 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
349 "write");
350 return GNUNET_SYSERR;
351 }
352 off += done;
353 }
338 return GNUNET_OK; 354 return GNUNET_OK;
339} 355}
340 356