I/O multiplexing

Source: Internet
Author: User

1. I/O model

An input operation typically consists of two different stages: waiting for data to be ready, copying data from the kernel to the process.

Blocking I/O models

Non-blocking I/O model

I/O multiplexing model: The kernel discovery process specifies that one or more I/O conditions are in place, and it notifies the process, supported by select and poll two functions

Signal-driven I/O model: The kernel sends a SIGIO signal notification process when the description word is ready

asynchronous I/O model: Let the kernel initiate an action and notify the process after the entire operation is complete

2. Select function

#include <sys/select.h>

#include <sys/time.h>

int select (int maxfdp1, fd_set *readset, Fd_set *writeset, fd_set *expectset, const struct Timeval *timeout)

The Select function specifies a series of descriptors that return after a descriptive word is ready or waiting for a specified time, returning all the number of descriptive words that are ready

Parameter timeout Specifies the maximum wait time, which is null when the function waits until there is a descriptive child ready

The parameters Readset, Writeset, and Expectset Specify the read, write, and exception condition descriptors for the kernel test. The type of these three parameters describes the word set fd_set, which can be

Use the following 4 macros:

void Fd_zero (Fd_set *fdset)

void fd_set (int fd,fd_set *fdset)

void fd_clr (int FD, fd_set *fdset)

int fd_isset (int FD, fd_set *fdset)//Determine if the FD descriptor in the Fdset descriptor set is ready

The Select function modifies the set of descriptors pointed to by Readset, Writeset, and Expectset, and the three parameters are value-result arguments, and when the function is called, the descriptive word of interest is specified,

When returned, indicates the ready description Word. Therefore, when you recall the Select function, you must reset the descriptor set

The value of MAXFDP1 is the maximum description Word plus 1

I/O multiplexing

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.