I have been familiar with this thing before, but I am not very clear about it. UNIX network programming provides a detailed explanation of the comparison between models and different models.
Because python is a simple call to Unix system functions, it is still fuzzy when I find UNIX network programming.
Select is a synchronous I/O operation and an I/O Reuse Model.
This function allows the process to instruct the kernel to wait for any of the multiple events to occur and wake up the process only when one or more events occur or after a specified time.
The model, such as recvfrom, is called by the system.
As described in this document
Select. Select (rlist, wlist, xlist [, timeout])
This is a straightforward interface to the Unix select () System Call. the first three arguments are sequences of 'waitable objects': either integers representing file descriptors or objects with a parameterless method named fileno () Returning such an integer:
Rlist: Wait until ready for reading
Wlist: Wait until ready for writing
Xlist: Wait for an "exceptional condition" (see the manual page for what your system considers such a condition
Empty sequences are allowed, but acceptance of three empty sequences is platform-dependent. (it is known to work on UNIX but not on Windows .) the optional timeout argument specifies a time-out as a floating point number in seconds. when the timeout argument
Is omitted the function blocks until at least one file descriptor is ready. A time-out value of zero specifies a poll and never blocks.
The return value is a triple of lists of objects that are ready: subsets of the first three arguments. when the time-out is reached without a file descriptor becoming ready, three empty lists are returned.
Among the acceptable object types in the sequences are Python file objects (e.g. SYS. stdin, or objects returned by open () or OS. popen (), socket objects returned by socket. socket (). you may also define a Wrapper class yourself, as long as it has an appropriate
Fileno () method (that really returns a file descriptor, not just a random integer ).
Note file objects on windows are not acceptable, but sockets are. on Windows, the underlying select () function is provided by the Winsock library, and does not handle file descriptors that don't originate from Winsock.
The general meaning in the document:
This is a simple interface that directly calls select () in UNIX. The first three parameters are a sequence of 'waiting object': an integer file descriptor or an integer returned by a non-parametric method fileno:
* Rlist wait till preparation
* Wlist waiting until the read is ready
* Xlist waits for an unexpected situation (in the manual, view the situation that your system recognizes)
Empty sequence is also allowed, but whether or not the three parameters are null is determined by your system. (We All Know That UNIX works, but Windows does not) the timeout parameter specifies a second-level floating point parameter, indicating the time-out time. When the timeout parameter is null, the function will be omitted to block until at least one file descriptor is ready.
The returned value is a list of three prepared parameters and a subset of the three parameter objects. If the request times out, three empty lists are returned. The parameter types that can be received in the list are file parameters in Python (for example, SYS. stdin or the return object of open () SYS. popen (), or the return object of socket. socket. You can also encapsulate a class as long as it is suitable for the fileno () method.
Note: In Windows, file objects are unacceptable, but socket is usable.
There is no explanation of the Principles.
Other network Materials
Ref: http://www.cnblogs.com/coser/archive/2012/01/06/2315216.html
- Select
- Select
- Select first appeared in. It monitors arrays of multiple file descriptors through a select () system call. When select () returns, the ready file descriptor in the array will be modified by the kernel so that the process can obtain these file descriptors for subsequent read/write operations.
- Currently, select supports almost all platforms, and its good cross-platform support is also an advantage. In fact, this is also one of its few advantages.
- One disadvantage of select is that there is a maximum limit on the number of file descriptors that a single process can monitor, which is generally 1024 in Linux, however, this restriction can be improved by modifying the macro definition or re-compiling the kernel.
- In addition, the data structure maintained by select () stores a large number of file descriptors. As the number of file descriptors increases, the overhead of copying also increases linearly. At the same time, due to the delay in network response time, a large number of TCP connections are inactive, but calling select () will perform a linear scan on all sockets, which also wastes a certain amount of overhead.
It is basically a description of some concepts.
The code is written by the teacher in the course. After understanding it, sort it out.