Page MenuHomePhabricator

ssh_channel_poll return 0 many times when handling a big SSH message in non-blocking mode
Open, Needs TriagePublic

Description

Hi,
I have used libssh to build an SSH server, it works well generally, thanks for your wonderful work.

Our server will try to poll a new message in a loop after it started, if there is no new message, it will switch to do some other works, if there is no work to do, it will sleep a short time(50ms).

As the title, ssh_channel_poll return 0 many times when handling a big SSH message in non-blocking mode, even if the message has alread been sent by the client. this cause that our server sleep many times (exactly 12 times), so the message is been delayed.

it seems this is caused in the function ssh_socket_pollcallback, in which there is a 4096-bytes buffer. libssh will only read 4096 bytes from the socket when user call ssh_channel_poll even if the client has sent the whole message. Then, ssh_channel_poll return 0 because this length is less than the size of the SSH message. After ssh_channel_poll is called many times (for me, 12 times), the whole message is been received, ssh_channel_poll return the size of this message (for me, 34990 bytes).