T258: ssh_channel_read_nonblocking() returns -127 rather than 0 on EOF
Description
Originally reported by johnboy2: https://bugs.libssh.org/T258
Whereas the documentation for ssh_channel_read_nonblocking()
says that 0 is returned on EOF, the actual return value is -127 (aka SSH_EOF
).
This appears to me to come from ssh_channel_read_nonblocking()
//expecting// ssh_channel_poll()
to only return non-negative values or SSH_ERROR. So when ssh_channel_poll()
instead returns SSH_EOF (which its own contract allows), ssh_channel_read_nonblocking()
returns that as-is --- which contradicts the documentation.
For the sake of compatibility, it might be easiest to update the documentation to reflect that SSH_EOF is returned on EOF, though trapping/replacing it with SSH_ERROR might also be reasonable.
Comments:
Jakuje commented on 2020-12-16 15:20:51 UTC:
What version of libssh are you using?
johnboy2 commented on 2020-12-16 16:19:57 UTC:
0.9.5
tmds commented on 2021-01-05 20:42:27 UTC:
This is a breaking change.
For example, it causes libgssh to return the eof as an error instead of eof. The last branch will be used instead of the first in:
if (is_eof)
{
g_debug ("channel eof");
g_task_return_int (prev_task, 0);
}
else if (rc > 0)
{
g_debug ("channel read %" G_GSSIZE_FORMAT " bytes", (gssize)rc);
g_task_return_int (prev_task, rc);
}
else
{
_gssh_set_error_from_libssh (&local_error, "Failed to read",
self->channel->connection->session);
g_task_return_error (prev_task, local_error);
}