Regarding the case where EAGAIN occurs during read(recv) execution in Socket Communication (TCP/Blocking I/O)

Asked 2 years ago, Updated 2 years ago, 128 views

In Socket Communication (TCP/Blocking I/O), when reading is performed with code similar to the following,

while((c=read(fileno(din), buf, bufsize))>0){
    // something to do
}

EAGAIN was mainly recognized when there was no data to read during non-blocking I/O, but
In the man below, SO_RCVTIMEO is also set during Blocking I/O, and read is
It can also be read to occur when a timeout occurs.
https://linuxjm.osdn.jp/html/LDP_man-pages/man7/socket.7.html

As mentioned above, are there any cases where EAGAIN occurs in Blocking I/O?
If so, what other cases exist besides the above?

linux c centos socket tcp

2022-09-30 18:13

1 Answers

You can assume the two cases mentioned in the question (for information on socket read, refer to the recvmsg documentation).There are two cases mentioned in the question)

Manpage of RECV

Quoted from Error section

EAGAIN or EWOULDBLOCK
The socket is set to nonblocking and the receive operation is stopped, or the receive timeout is set to expire before receiving data.
POSIX.1-2001 allows either error to be returned in this case and does not require these two constants to have the same value.
Therefore, applications that require portability should check both possibilities.


2022-09-30 18:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.