From libssh2_channel_write_ex
man page:
Actual number of bytes written or negative on failure. LIBSSH2_ERROR_EAGAIN when it would otherwise block. While LIBSSH2_ERROR_EAGAIN is a negative number, it isn't really a failure per se.
Now I have a problem with that. When I receive LIBSSH2_ERROR_EAGAIN
does it mean that nothing was sent and that I must resend all data? Or does it mean that some data have been sent
My problem is that if I'm trying to send more dat开发者_JS百科a that the underlying socket can hold, write()
should block anyway, henceforth how can I hope to send a big block of data without getting LIBSSH2_ERROR_EAGAIN
every time?
LIBSSH2_ERROR_EAGAIN Will occur if no data has been sent which you have it in buffer. You Can send it again after Checking whether the socket is alive by using Select(). If Select() returns the event, you handle it appropriately and you can resend it.
Loop goes like this
do
{
While (rc = libssh2_Channel_write_ex () == LIBSSH2_ERROR_AGAIN )
{
if(!select()) // Wait for timeout
//Timeout
}
if(rc>0)
//Read next set of data into buffer for sending
else if(rc <0)
// Libssh2 error
}
LIBSSH2_ERROR_EAGAIN means nothing was sent and you must send it all again. If something was sent, that number would be returned instead.
精彩评论