socket concept

Whether socket, or FIFO, pipelines, terminals, for us, everything is a file, everything flows. During the information exchange, we are those transmitting and receiving operation of data streams, referred to as I / O operations (input and output), to the stream data is read system call read, write system call write. But having said that, there are so many computer stream, how do I know which stream to operate it? Pair, where the file descriptors, known as fd, fd a is an integer, so that the operation of the integer, is to this file (stream). We create a socket, through the system call returns a file descriptor, then the rest of the operation of the socket will be transformed into the operation of this descriptor. Not say that this is a kind of layered and abstract thinking.
Synchronous IO, is a call initiated by way of user space and kernel space. IO synchronization refers to the user space threads are party to initiate IO requests, the kernel space is a passive recipient.
Asynchronous IO is, in turn, means the kernel is the kernel initiates party IO request, the user thread is a passive recipient.
Blocking IO, referring to the need to complete a thorough Core IO operation, before returning to user space, perform user operation. Blocking refers to the execution status of the user space program, space program user needs to wait for IO operations fully completed. The traditional IO models are synchronous blocking IO.
Nonblocking IO, refers to the user does not need to wait for the IO core operation is complete, the kernel immediately returns a status value to the user, the user need not wait for the kernel space IO operation fully completed, the user can immediately return space, the user performs an operation, in non-blocking state.
I / O multiplexing it through a mechanism, you can monitor multiple descriptors, once a descriptor is ready, the program can be notified of the corresponding operation.
nature select to employ 32-bit integers 32, or 32 32 = 1024 is identified, the value FD 1-1024. When the value fd of more than 1,024 limit, you must modify the FD_SETSIZE size. This time it can identify 32 max FD value range.
poll and select different events through a concern pollfd array transmitted to the kernel, it does not describe the number of qualifiers, events and the revents pollfd field for indicating respectively the events of interest and events, so that the array requires only pollfd It is initialized once.
one kind or poll epoll optimization does not need to traverse all the fd returns, maintain a list of fd in the kernel. select and poll list is maintained in the user mode kernel, and then passed to the kernel. And poll / select different, epoll is no longer a single system call, but by epoll_create / epoll_ctl / epoll_wait composed of three system calls, later will see the benefits of doing so. epoll is supported in the 2.6 kernel later.

Guess you like

Origin blog.51cto.com/3314808/2453524