这是在 Ubuntu 12.04 上发生的。相同的代码在 OSX 上运行良好。
在下面的日志中,您可以看到 SO_SNDBUF 是 20440,并且有几个 send() 在因 EAGAIN 失败之前成功。
wsmux started on port 8888
send buffer size = 20440
open wsmux:187.59.165.86-16580
send 129, result 129, errno 115
message wsmux:187.59.165.86-16580 NICK zxc5239
message wsmux:187.59.165.86-16580 USER zxc zxc zxc zxc
message wsmux:187.59.165.86-16580 JOIN #a
send 2, result 2, errno 115
send 66, result 66, errno 115
send 2, result 2, errno 115
send 42, result 42, errno 115
send 2, result 2, errno 115
send 100, result 100, errno 115
send 2, result 2, errno 115
send 43, result 43, errno 115
send 2, result 2, errno 115
send 48, result 48, errno 115
send 2, result -1, errno 11
close wsmux:187.59.165.86-16580 Resource temporarily unavailable
唯一启用的套接字选项是 TCP_NODELAY 和 O_NONBLOCK。 这可能是什么问题?
有问题的代码:
最佳答案
如果你有 O_NONBLOCK
那么每次调用 send
和 recv
都会失败并返回 EAGAIN
,因为你设置了非阻塞套接字(这仅意味着调用会阻塞)。这不是错误,不应作为一个错误处理。它在手册页中明确解释,例如发送
。
关于c - 仅发送几百个字节后 send() 因 EAGAIN 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17924923/