1

这发生在 Ubuntu 12.04 上。相同的代码在 OSX 上运行良好。

在下面的日志中,您可以看到 SO_SNDBUF 是 20440,并且在 EAGAIN 失败之前,有几个 send()s 成功。

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。这里可能是什么问题?

有问题的代码:

4

2 回答 2

0

如果您O_NONBLOCK每次调用都send可以recv失败EAGAIN,因为您设置了非阻塞套接字(这只意味着调用会阻塞)。这不是一个错误,不应该作为一个错误来处理。它在手册页中明确解释,例如send.

于 2013-08-05T10:03:44.233 回答
0

TCP_NODELAY导致每个都send立即发送数据以及所有 TCP/IP 标头。如果您对每 2 个字节的数据包继续这样做,您将很快遇到EAGAIN,因为远程端必须先ACK接收数据包,然后才能发送新的数据包。更不用说它也非常低效!2字节的数据包真的很紧急吗?

于 2013-09-08T10:08:42.917 回答