C/C ++ on Liunx platform Article 2: I/O

Source: Internet
Author: User

UNIX APIs provide the most basic IO functions and are declared in fcntl. h unistd. h. (Fcntrl <=> fd control)
The application uses file descriper (file descriptor) to interact with the kernel.
These functions are called unbuffered I/O.
In UNIX, everything is a file. Files and sockets on disks can be identified by FD, or these functions can be used to operate I/O.
Common unix io models (Part 1 ):
1. blocking IO
2. Non-blocking IO
3. IO Reuse
When opening a file, the default I/O method is blocking.
Function prototype:
Ssize_t read (int, void *, size_t); //-1 error, 0 EOF
Ssize_t write (int, void *, size_t );
Read and write are usually put in a loop, and the error or EOF is break.
In socket IO, if it is blocking mode, when reading, if the kernel is not ready for data, the read function will be blocked and a thread is needed for processing.
IO multiplexing technology allows the server to allocate two threads for each client.
<To be continue...>


 

From leonzhang

Related Article

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.