Linux I/O model (5)-select-xuan Mai blade-blog
Linux I/O model (5)-select of Io Reuse Model
By Xuan Mai blade, 1177 read, 0 comments, favorites, Edit
The first thing you need to know is the select function:
Select Function
# Include <sys/select. h>
# Include <sys/time. h>
Int select (INT maxfd, fd_set * readset, fd_set * writeset, fd_set * predictionset, const struct timeval * timeout );
Return: the number of vertices in the ready description. Value 0 indicates timeout, and value-1 indicates an error.
Parameter description:
Maxfd: the largest file descriptor (the value should be the largest file descriptor word + 1)
Readset: a set of Descriptor words for Kernel read Operations
Writeset: a set of Descriptor words for Kernel write operations
Predictionset: a set of Descriptor words for Kernel exception operations
Timeout: How long does it take to wait for the descriptor to be ready. Null indicates waiting forever. A fixed value indicates waiting for a fixed time. 0 indicates not waiting at all. Return immediately after checking the description.
Note: readset, writeset, and predictionset are both value-result parameters, which means they are passed into the pointer. The function can modify the corresponding fd_set according to the pointer.