gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 15:29:53 32 4
gpt4 key购买 nike

我有一个等待 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com