From 7c28d8d6a6a55baa18abdc83bbcdb2eba8ef6bb6 Mon Sep 17 00:00:00 2001 From: ben Date: Sun, 30 Sep 2007 12:45:49 +0000 Subject: [PATCH] When writing session data to stdout or stderr, switch the relevant file descriptor into non-blocking mode temporarily, and correctly handle returns of EAGAIN from write(). This should fix unix-plink-stdout-nonblock, while avoiding EAGAIN turning up where we aren't expecting it. git-svn-id: svn://svn.tartarus.org/sgt/putty@7748 cda61777-01e9-0310-a592-d414129be87e --- unix/uxplink.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/unix/uxplink.c b/unix/uxplink.c index a1dac9ad..9d5f0016 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -389,16 +389,21 @@ void try_output(int is_stderr) bufchain *chain = (is_stderr ? &stderr_data : &stdout_data); int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO); void *senddata; - int sendlen, ret; + int sendlen, ret, fl; if (bufchain_size(chain) == 0) return; bufchain_prefix(chain, &senddata, &sendlen); + fl = fcntl(fd, F_GETFL); + if (fl != -1 && !(fl & O_NONBLOCK)) + fcntl(fd, F_SETFL, fl | O_NONBLOCK); ret = write(fd, senddata, sendlen); + if (fl != -1 && !(fl & O_NONBLOCK)) + fcntl(fd, F_SETFL, fl); if (ret > 0) bufchain_consume(chain, ret); - else if (ret < 0) { + else if (ret < 0 && errno != EAGAIN) { perror(is_stderr ? "stderr: write" : "stdout: write"); exit(1); } -- 2.11.0