Improve ssh reading and detect eof or error

This commit is contained in:
oupson 2023-02-26 16:31:25 +01:00
parent d0f95935a9
commit b0d9a18006
Signed by: oupson
GPG Key ID: 3BD88615552EFCB7
1 changed files with 13 additions and 6 deletions

View File

@ -157,13 +157,20 @@ namespace FooTerm {
}
try {
ssize_t size = 0;
var buffer = new uint8[1024];
var size = this.channel.read(buffer);
debug("Got %zu from ssh", size);
do {
size = this.channel.read(buffer);
if (size > 0) {
debug("Got %zd bytes from ssh", size);
if (Posix.write(this.slave_pty, buffer, size) < 0) {
throw GLib.IOError.from_errno(Posix.errno);
}
} else if ((size == 0 && channel.eof() != 0) || (size < 0 && size != SSH2.Error.AGAIN)) {
warning("Channel is closed");
return false;
}
} while(size != SSH2.Error.AGAIN);
return true;
} catch(Error e) {