summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-01-30 15:29:59 -0500
committerNick Mathewson <nickm@torproject.org>2015-01-30 15:29:59 -0500
commitaba90b2125725a2d870a847482e30d78a1a2582d (patch)
treedeba5c09c7368a67ff9e790cf4db2f0a884a271c /src
parent097286e47665a32e54249f809c23e190be9d57e8 (diff)
parent2c41f120481b7b14fcf0ef3aaf78d84f47178cb7 (diff)
downloadtor-aba90b2125725a2d870a847482e30d78a1a2582d.tar.gz
tor-aba90b2125725a2d870a847482e30d78a1a2582d.zip
Merge remote-tracking branch 'dgoulet/bug14554_026_v1'
Diffstat (limited to 'src')
-rw-r--r--src/common/compat_threads.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/common/compat_threads.c b/src/common/compat_threads.c
index d2d929e430..15648d2851 100644
--- a/src/common/compat_threads.c
+++ b/src/common/compat_threads.c
@@ -171,10 +171,12 @@ pipe_drain(int fd)
{
char buf[32];
ssize_t r;
- while ((r = read_ni(fd, buf, sizeof(buf))) >= 0)
- ;
- if (r == 0 || errno != EAGAIN)
+ do {
+ r = read_ni(fd, buf, sizeof(buf));
+ } while (r > 0);
+ if (r < 0 && errno != EAGAIN)
return -1;
+ /* A value of r = 0 means EOF on the fd so successfully drained. */
return 0;
}
#endif
@@ -193,10 +195,12 @@ sock_drain(tor_socket_t fd)
{
char buf[32];
ssize_t r;
- while ((r = recv_ni(fd, buf, sizeof(buf), 0)) >= 0)
- ;
- if (r == 0 || !ERRNO_IS_EAGAIN(tor_socket_errno(fd)))
+ do {
+ r = recv_ni(fd, buf, sizeof(buf), 0);
+ } while (r > 0);
+ if (r < 0 && !ERRNO_IS_EAGAIN(tor_socket_errno(fd)))
return -1;
+ /* A value of r = 0 means EOF on the fd so successfully drained. */
return 0;
}