From 8e9e5d8e9109e8a690dafccd6c90bdfab29bc79b Mon Sep 17 00:00:00 2001 From: angt Date: Mon, 2 Nov 2015 12:44:57 +0100 Subject: [PATCH] Call poll() only when it's needed in fd_{read,write}_all() --- glorytun.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/glorytun.c b/glorytun.c index e346542..12402cc 100644 --- a/glorytun.c +++ b/glorytun.c @@ -269,15 +269,17 @@ static ssize_t fd_read_all (int fd, void *data, size_t size) }; while (done0) - done += ret; + if (ret<0) { + poll(&pollfd, 1, -1); + continue; + } + + done += ret; } return done; @@ -293,15 +295,17 @@ static ssize_t fd_write_all (int fd, const void *data, size_t size) }; while (done0) - done += ret; + if (ret<0) { + poll(&pollfd, 1, -1); + continue; + } + + done += ret; } return done;