- 论坛徽章:
- 0
|
如果是read()报EAGAIN(11)错误,则以下是出错的原因。
ERRORS
The read(), readv(), and pread() functions will fail if:
EAGAIN Mandatory file/record locking was set,
O_NDELAY or O_NONBLOCK was set, and there
was a blocking record lock; total amount of
system memory available when reading using
raw I/O is temporarily insufficient; no data
is waiting to be read on a file associated
with a tty device and O_NONBLOCK was set; or
no message is waiting to be read on a stream
and O_NDELAY or O_NONBLOCK was set.
这里面提到了很多种可能,估计对于你的应用,你有可能属于最后一种情况,即你是以O_NDELAY或者O_NONBLOCK方式打开了一个流,你希望从上面读消息,但目前没有消息,由于是非阻塞方式,所以read()仍然返回,但返回值为-1,且errno被设为EAGAIN。如果是这种情况,则是正常的。不过你可以通过select()方式来测试某个socket是否有输入,然后再去读,这样会好一些。 |
|