Reputation: 2225
Posix supports blocking and non-blcoking file descriptors. Second ones may be opened with O_NONBLOCK
flag. I have a main loop in my app, which polls some set (poll
sys call) of file descriptors for POLLIN
and POLLOUT
events. May I still use blocking file descriptors, cause I write only when POLLOUT
is set and read only when POLLIN
is set?
Upvotes: 4
Views: 708
Reputation: 2225
Accroding to poll(2) man page:
POLLOUT Writing is now possible, though a write larger that the available space in a socket or pipe will still block (unless O_NONBLOCK is set).
In other words: if there is not enough space in kernel buffer associated with this fd, writing a chunk of data, larger than space available in buffer would block. If there is space available they behave identically.
So you must set all your file descriptors to be non-blocking, especially TCP sockets, cause if the process on the other side has slow connection you may face blocking write call, until client won't send you back all ACKs for every IP package.
Upvotes: 5