可以从套接字 return EWOULDBLOCK 读取()吗?

Can read() from socket return EWOULDBLOCK?

我的代码使用 epoll 进行多路复用。遇到 EPOLLIN 后,它从就绪套接字中读取一个字节。

read(fd, &onebyte, 1);

上面那行可以returnEWOULDBLOCK吗?

是的,

Errors:

...

EAGAIN or EWOULDBLOCK

The file descriptor fd refers to a socket and has been marked nonblocking (O_NONBLOCK), and the read would block. POSIX.1-2001 allows either error to be returned for this case, and does not require these constants to have the same value, so a portable application should check for both possibilities

参考: the read() man description