Reputation: 4526
Mostly select()
is straightforward in terms of what flags get set:
But there are plenty of exceptions (or, perhaps, nontrivial extensions) to this rule: 'w' is set for a nonblocking connect that's completed, 'r' is set for a listen()
with a pending accept()
, and so on.
Has anyone found a straightforward list of what flags get set in what circumstances?
Upvotes: 2
Views: 166
Reputation: 160
reference for select, which provide suggestion for usage of select
http://man7.org/linux/man-pages/man2/select_tut.2.html
Upvotes: 0
Reputation: 409422
From this reference page:
A descriptor shall be considered ready for reading when a call to an input function with
O_NONBLOCK
clear would not block, whether or not the function would transfer data successfully. (The function might return data, an end-of-file indication, or an error other than one indicating that it is blocked, and in each of these cases the descriptor shall be considered ready for reading.)A descriptor shall be considered ready for writing when a call to an output function with
O_NONBLOCK
clear would not block, whether or not the function would transfer data successfully.If a socket has a pending error, it shall be considered to have an exceptional condition pending. Otherwise, what constitutes an exceptional condition is file type-specific.
Except for descriptors in the exceptional set, it's pretty clear. If a blocking descriptor (no matter if it's a file, a socket, or some other descriptor) will not block, then it's marked as ready in its respective set. Accepting and receiving are "read" operations, while connection and writing are "write" operations.
The only problematic thing are the exceptional states, which depends on the type of descriptor you pass in the set.
Upvotes: 2