【问题标题】:Asynchronous socket send on LinuxLinux 上的异​​步套接字发送
【发布时间】:2011-08-03 17:51:00
【问题描述】:

当异步套接字上的发送返回 EAGAIN 时,这是否意味着: 当前呼叫刚刚成功排队,还是因为系统仍在处理先前的发送而什么也没做?

提前谢谢你。

【问题讨论】:

    标签: c++ linux sockets asynchronous send


    【解决方案1】:

    来自man 2 send

    套接字被标记为非阻塞,请求的操作将阻塞。 POSIX.1-2001 允许在这种情况下返回任一错误,并且不要求此常量 [EAGAIN EWOULDBLOCK] 具有相同的值,因此可移植应用程序应检查这两种可能性。

    所以,我认为EAGAIN 的意思是:be careful, the message did not fit into send buffer, this call would be blocked in normal (blocking) mode. Use select(2) to determine whether you can send more data.

    附:实际上,看起来调用失败了,什么也没做。

    【讨论】:

      【解决方案2】:

      什么都没做。

      如果某事已完成,返回值会告诉您发送了多少字符。当您获得返回值 -1 和 errno=EAGAIN 时,没有发送任何内容。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-08
        • 1970-01-01
        • 2015-10-27
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多