I'm trying to learn about Linux I/O. Recently I was going through the manual page of epoll
system call and I notice that a file descriptor can be notified if it is available for writing via EPOLLOUT
event. I'm trying to understand when is this possible that a non-blocking file descriptor fd
is not available for writing, i.e., the system call,
ssize_t bytes_written = write(fd, buff, SIZE_OF_DATA_TO_WRITE)
returns bytes_written
to be -1 and sets errno
to be EAGAIN
. I want to know when is the above condition possible? Is it like when the server is expecting a read() but client issues a write() call or if either the server/client has closed the socket and the other party is trying to write to the socket? Or is it something else entirely?
Note: I'll be talking about file descriptors in terms of network sockets and not files on disk. I know that writing to a disk will in general not result in the condition mentioned above.