c - Errno 35 (EAGAIN) 在 recv 调用时返回

标签 c macos sockets

我有一个等待 recv 的套接字,然后在接收到数据后,向前发送数据进行处理。然而,然后它再次进行 recv,这次它没有收到任何返回 -1,当打印 errno 时它打印 35(即 EAGAIN)。

这只发生在 MAC OS Lion 操作系统上,对于其他操作系统,它运行得很好

do{
 rc = recv(i, buffer, sizeof(buffer), 0);
 if (rc < 0){
      printf("err code %d", errno); 
 }
 if(rc == 0){ 
      //Code for processing the data in buffer 
      break; 
 } 
      ....
}while(1);

编辑:更正缩进和错误

最佳答案

您要么将套接字设置为非阻塞模式,要么启用接收超时。这是来自 recv(2)在 Mac 上:

The calls fail if:

[EAGAIN] The socket is marked non-blocking, and the receive operation would block, or a receive timeout had been set, and the timeout expired before data were received.

编辑0:

嗯,抱歉再次引用。这次来自intro(2) :

11 EDEADLK Resource deadlock avoided. An attempt was made to lock a system resource that would have resulted in a deadlock situation.

...

35 EAGAIN Resource temporarily unavailable. This is a temporary condition and later calls to the same routine may complete normally.

只需使用 strerror(3)找出实际问题。

关于c - Errno 35 (EAGAIN) 在 recv 调用时返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14595269/

相关文章:

c - 遍历C指针列表: weird printf behaviour

c - C 中的字符串化运算符不适用于 linux

c++ - 是否返回 void 有效代码?

c - 无法传输二进制文件

php - 如果unread_bytes == 0,则取消阻塞fread(),而不会使流连接超时

c - *** 错误 : double free or corruption (out): 0x00007fffe3465010 ***. 警告 : Corrupted shared library list: 0x7ffea4000920 ! = 0x7ffff7ffd9d8

c++ - 在 Mac 上通过 HTTP/HTTPS 和/或 FTP/FTPS 上传文件

python - 由于系统 Python 2.7 的要求,Pygame 安装失败,即使我有 Python 2.7

oracle - 在Mac OSX Yosemite上为Docker提供更多交换空间

C# 通用 Windows StreamSocket 客户端未连接到 StreamSocketListener 服务器