c - 仅发送几百个字节后 send() 因 EAGAIN 失败

标签 c linux sockets libev

这是在 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 那么每次调用 sendrecv 都会失败并返回 EAGAIN,因为你设置了非阻塞套接字(这仅意味着调用会阻塞)。这不是错误,不应作为一个错误处理。它在手册页中明确解释,例如发送

关于c - 仅发送几百个字节后 send() 因 EAGAIN 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17924923/

相关文章:

c - 父 c 中 wait() 的目的

c - 如何将从文件输入的整数网格转换为字符串网格

java - 播放框架 tmp 磁盘已满类文件

Linux 操作系统类的内容

c++ - 获取远程地址/IP - C Berkeley Sockets

c++ - 文件处理,复制内容时插入 ÿ 字符

java - Eclipse 快速提示不会在 Linux Ubuntu 和 Centos 中显示 "import"建议

java objectinputstream中的readObject如何知道要读取多少字节?

java - Java猜数字游戏(客户端和服务器)。输入非整数时,会发生SocketException错误

c - 通过 fscanf() 读取的值未打印出来