通道未阻塞时 libssh2_channel_write 的行为

发布于 2024-10-26 09:52:31 字数 406 浏览 2 评论 0原文

来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

草莓酥 2024-11-02 09:52:31

LIBSSH2_ERROR_EAGAIN 如果缓冲区中没有数据发送,则会发生此情况。您可以使用 Select() 检查套接字是否处于活动状态后再次发送。
如果 Select() 返回事件,您可以适当地处理它并且可以重新发送它。

循环是这样的

    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 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
    }
灼痛 2024-11-02 09:52:31

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文