Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can read() from socket return EWOULDBLOCK?

My code uses epoll for multiplexing. After EPOLLIN is encountered it reads one byte from ready socket.

read(fd, &onebyte, 1);

Can the above line return EWOULDBLOCK?

like image 652
jorge is not ai Avatar asked Jul 27 '26 13:07

jorge is not ai


1 Answers

yes,

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

reference: the read() man description

like image 182
Green Avatar answered Jul 29 '26 06:07

Green



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!