|
How select() works
- A file descriptor is associated with a file structure.
- In the file structure, there is a set of operations supported by this file type called file_operations.
- In the file_operations structure, there is an entry named poll.
- What the generic select() call does is call this poll() function to get status of a file (or socket or whatever) as the name suggests.
- In general, the select() works like
- while(1)
- {
- for each file descriptor in the set
- {
- call file's poll() to get mask.
- if(mask & can_read or mask & can_write or mask & exception)
- {
- set bit for this fd that this file is readable/writable or there is an
- exception.
- retval++;
- }
- }
- if(retval != 0)
- break;
- schedule_timeout(__timeout);
- }
- For detailed implementation of select(), please take a look at sys_select() and do_select() in fs/select.c. of standard kernel source code.
- Another thing required to understand is poll_wait(). What it does is put current process into a wait
- queue provided by each kernel facilities such as file or pipe or socket or in our case, message queue.
- Please note that the current process may wait on several wait queues by calling select()
复制代码 |
|