Linux I/O multi-channel transfer model and select ()

Source: Internet
Author: User

Linux I/O multi-channel Transfer Model:

In this model, if the requested I/O operation is blocked, it does not actually block I/O, but waits for one of the functions. During this period, i/O can also perform other operations. Select () and Poll () belong to this model.

 

Select () function description

Header file

# Include <sys/types. h>

# Include <sys/time. h>

# Include <unistd. h>

Prototype Int select (INT numfds, fd_set * readfds, fd_set * writefds, fd_set * exeptfds, struct timeval * timeout
Parameters

Numfds: file descriptor with the highest number to be checked + 1

Readfds: a set of read file descriptors monitored by select ().

Writefds: a set of write file descriptors monitored by select ().

Exeptfds: a collection of exception handling file descriptors monitored by select ()

Timeout:

--- NULL: always wait until the signal or file descriptor is captured.

--- Specific value: struct timeval pointer. If the timeout time is not ready, return immediately

--- 0: Never wait. test all specified descriptors and return immediately

Return Value

Success: The file descriptor is ready.

-1: Error

 

Four macros for file descriptor operations:

Fd_zero (fd_set * Set) Clears a file descriptor set.
Fd_set (int fd, fd_set * Set) Add a file descriptor to the file descriptor set
Fd_clr (int fd, fd_set * Set) Delete a file descriptor from the collection
Fd_isset (int fd, fd_set * Set) Test whether a given location in the SET has changed

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.