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