通道未阻塞时 libssh2_channel_write 的行为
来自 libssh2_channel_write_ex 手册页:
实际写入的字节数或 对失败持消极态度。 LIBSSH2_ERROR_EAGAIN 当它会 否则阻止。尽管 LIBSSH2_ERROR_EAGAIN 是负数 数字,这并不是真正的失败 硒。
现在我有一个问题。当我收到 LIBSSH2_ERROR_EAGAIN
时,是否意味着未发送任何内容并且我必须重新发送所有数据?或者这是否意味着某些数据已发送
我的问题是,如果我尝试发送底层套接字可以容纳的更多数据,write()
无论如何都应该阻塞,今后我如何希望发送大块数据而不每次都得到LIBSSH2_ERROR_EAGAIN
?
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 data 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LIBSSH2_ERROR_EAGAIN 如果缓冲区中没有数据发送,则会发生此情况。您可以使用 Select() 检查套接字是否处于活动状态后再次发送。
如果 Select() 返回事件,您可以适当地处理它并且可以重新发送它。
循环是这样的
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
LIBSSH2_ERROR_EAGAIN 表示未发送任何内容,您必须再次发送全部内容。如果发送了某些内容,则会返回该号码。
LIBSSH2_ERROR_EAGAIN means nothing was sent and you must send it all again. If something was sent, that number would be returned instead.