]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
When writing session data to stdout or stderr, switch the relevant file
authorBen Harris <bjh21@bjh21.me.uk>
Sun, 30 Sep 2007 12:45:49 +0000 (12:45 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Sun, 30 Sep 2007 12:45:49 +0000 (12:45 +0000)
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.

[originally from svn r7748]

unix/uxplink.c

index a1dac9adc8af819f5a7e82e58e16bd794c029eaf..9d5f001615b7a200919c8e05642f30f2bd622aa2 100644 (file)
@@ -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);
     }