mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-16 03:53:01 -05:00
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. [originally from svn r7748]
This commit is contained in:
parent
17bc691cc2
commit
c5996bcde5
@ -389,16 +389,21 @@ void try_output(int is_stderr)
|
|||||||
bufchain *chain = (is_stderr ? &stderr_data : &stdout_data);
|
bufchain *chain = (is_stderr ? &stderr_data : &stdout_data);
|
||||||
int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO);
|
int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO);
|
||||||
void *senddata;
|
void *senddata;
|
||||||
int sendlen, ret;
|
int sendlen, ret, fl;
|
||||||
|
|
||||||
if (bufchain_size(chain) == 0)
|
if (bufchain_size(chain) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bufchain_prefix(chain, &senddata, &sendlen);
|
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);
|
ret = write(fd, senddata, sendlen);
|
||||||
|
if (fl != -1 && !(fl & O_NONBLOCK))
|
||||||
|
fcntl(fd, F_SETFL, fl);
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
bufchain_consume(chain, ret);
|
bufchain_consume(chain, ret);
|
||||||
else if (ret < 0) {
|
else if (ret < 0 && errno != EAGAIN) {
|
||||||
perror(is_stderr ? "stderr: write" : "stdout: write");
|
perror(is_stderr ? "stderr: write" : "stdout: write");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user