本文介绍了OSX上虚假的recv()EAGAIN?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题已解决,我之前在服务器套接字上错误地调用了fcntl(sock,F_SETFL,FD_CLOEXEC).由于FD_CLOEXEC是用于F_SETFD而不是F_SETFL的,并且以某种方式映射到包含O_NONBLOCK的掩码,所以也被继承到客户端套接字.

Problem solved, I earlier incorrectly called fcntl(sock, F_SETFL, FD_CLOEXEC) on the server socket. This somehow got mapped to a mask containing O_NONBLOCK because FD_CLOEXEC is for F_SETFD, not F_SETFL and was inherited to client sockets too.

你好

我正在Mac OS X 10.4上开发网络应用程序.这里发生了一些奇怪的事情:有时-非常有规律且可靠地-在阻塞的TCP套接字上的recv()操作返回-1,而errno设置为EAGAIN.

I'm developing a networking application on Mac OS X 10.4. Something strange is happening here: Sometimes - pretty regularly and reliably - a recv() operation on a blocking TCP socket returns -1 with errno being set to EAGAIN.

这很奇怪,因为如上所述,它是一个阻塞套接字.我也没有设置任何接收超时-作为文档状态也可能导致EAGAIN返回.我使用getsockopt()来验证没有超时.如果我拍了一个usleep()并再次调用recv(),那么接下来的数据就可以了.

This is very strange because, as stated, it is a blocking socket. Nor have I set any receive timeouts - which as the docs state can also cause an EAGAIN return. I used getsockopt() to verify that there is no timeout. If I slap in a usleep() and call recv() again, then I get data the next data just fine.

以前有没有人在OSX或其他系统上遇到过此问题?

Has anyone encountered this before on OSX specifically or on other systems?

此应用程序非常简单.它是单线程的,不使用任何信号,也没有异步I/O.

This application is pretty simple. It is single-threaded, makes no use of singals, there is no asynchronous I/O going on.

推荐答案

我发现了我的错误:

我叫fcntl(fd,F_SETFL,FD_CLOEXEC);当我应该为该标志使用F_SETFD时:-(

I called fcntl(fd, F_SETFL, FD_CLOEXEC); when I should have used F_SETFD for this flag :-(

我不知道它是如何精确地映射到包含O_NONBLOCK的蒙版的-因为它们具有不同的值-但这就是发生的情况.

I don't know how exactly this got mapped to a mask containing O_NONBLOCK - because they have different values - but that's what happened.

感谢您的时间.

这篇关于OSX上虚假的recv()EAGAIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 23:31