什么会导致sock send()命令中的“资源暂时不可用”
什么会导致一个套接字send()命令Resource temporarily unavailable错误? 套接字被设置为AF_UNIX, SOCK_STREAM 。 它大部分时间都是有效的,但偶尔会出现这个错误。 sockets的接收端似乎正常工作。
我知道这不是很详细,但我只是在寻找一般的想法。 谢谢!
"Resource temporarily unavailable"是对应于EAGAIN的错误信息,这意味着操作将被阻塞,但是请求非阻塞操作。 对于send() ,这可能是由于以下任何原因:
- 用
fcntl()明确标记文件描述符为非阻塞; 要么 - 将
MSG_DONTWAIT标志传递给send(); 要么 - 使用
SO_SNDTIMEO套接字选项设置发送超时。
这是因为你正在使用一个non-blocking套接字,输出缓冲区已满。
从send()手册页
When the message does not fit into the send buffer of the socket, send() normally blocks, unless the socket has been placed in non-block- ing I/O mode. In non-blocking mode it would return EAGAIN in this case.
EAGAIN是与“资源暂时不可用”绑定的错误代码
考虑使用select()来更好地控制这些行为