epoll 事件 epollin 发生,第一次recv 是EAGAIN?

我用epoll_wait监听读写事件,当发生epollin事件的时候,我立即对该fd进行recv,但是第一次recv的时候直接EGAIN了(fd是非阻…
关注者
5
被浏览
3,598
登录后你可以
不限量看优质回答私信答主深度交流精彩内容一键收藏

非阻塞socket的方式下,EPOLLIN事件并不一定表示有数据,recv的man手册上提到:If no messages are available at the socket, the receive calls wait for a message to arrive, unless the socket is nonblocking (see fcntl(2)), in which case the value -1 is returned and the external variable errno is set to EAGAIN or EWOULDBLOCK.

errno为EAGAIN继续等下一个事件处理即可,具体可看这里:

nonblocking socket recv problem while using it with epoll