Introduction to the Linux network I/O model

Source: Internet
Author: User

I. Getting Started with I/O basics

Earlier versions prior to java1.4, Java's support for I/O was imperfect, and developers faced some great challenges and difficulties in developing high-performance I/O programs, the main issues being as follows.

1, useless data buffer, I/O performance problems;

2. There is no channel concept in C or C + +, only input and output streams;

3, synchronous blocking type I/O communication (BIO), usually causes the communication thread to be blocked for a long time;

4, support character set is limited, hardware portability is not good.

Ii. Introduction to the Linux network I/O model

The Linux kernel says that all external devices are treated as a file, and that reading and writing to a file invokes the kernel-supplied system commands, returning a file descriptor (FD, filename descriptor).

and read and write to a socket will also have a corresponding descriptor, called SOCKETFD (Socket descriptor), the descriptor is a number, it points to a structure in the kernel (file path, data area and other properties).

UNIX provides 5 I/O models based on UNIX network programming for the classification of I/O models.

1. Blocking IO Model: By default, all file operations are blocked. Call Recvfrom in process space, whose system call knows when the packet arrives and is copied to the buffer of the application process or if an error occurs.

During this period, the process is blocked for the entire period of time from call Recvfrom to its return, so it is called a blocking I/O model.

2, non-blocking IO Model: Recvfrom from the application layer to the kernel, if the buffer does not have data, it will return a ewouldblock error, generally the non-blocking IO model Polling check this state,

See if the kernel has data coming.

Introduction to the Linux network I/O model

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.