堵塞socket 就是在accept、read、write等IO操作的的时候,如果没有可用符合条件的资源,不马上返回,一直等待直到有资源为止。
非堵塞socket 则是在执行select的时候,当没有资源的时候堵塞,当有符合资源的时候,返回一个信号,然后程序就可以执行accept、read、write等操作,这个时候,这些操作是马上完成,并且马上返回。
而windows的winsock则有所不同,可以绑定到一个EventHandle里,也可以绑定到一个HWND里,当有资源到达时,发出事件,这时执行的io操作也是马上完成、马上返回的。一般来说,
如果使用堵塞socket,通常我们时开一个线程accept socket,当有socket链接的时候,开一个单独的线程处理这个socket;
如果使用非堵塞socket,通常是只有一个线程,一开始是select状态,当有信号的时候马上处理,然后继续select状态。 ioctlsock()设置套接字的阻塞和非阻塞模式 _______________________________________________________________________________
一组网络服务原语
listen 阻塞操作,等待一个进入的连接
connect 与一个正在等待的对等体建立连接
receive 阻塞操作,等待一个进入的报文
send 约会对等体发送一个报文
disconnect 终止一个连接
_______________________________________________________________________________
Receives data from a datagram or stream socket.
int lrs_receive ( char *s_desc, char *bufindex, [char *flags], LrsLastArg );
s_desc
|
A descriptor identifying a connected socket.
|
buffer
|
A descriptor identifying a buffer.
|
flags
|
Receive and Send Flags that specify various ways which the call can be made (optional). Use the following format: "Flags= flags"
|
LrsLastArg
|
A marker indicating the end of the parameters (used where optional parameters are available).
|
The lrs_receive function reads the incoming data from a datagram or stream socket. If no incoming data is available at the socket, lrs_receive waits for data to arrive unless the socket is non-blocking.
VuGen determines the expected size of the buffer from the recorded session. If the buffer size does not match (smaller or larger), lrs_receive rereads the incoming data carried by the socket, until the receive_timeout. By default the receive_timeout is 10 seconds. You can modify the timeout using lrs_set_recv_timeout or lrs_set_recv_timeout2.
Note that the successful completion of a lrs_receive does not indicate that all of the data was successfully received. If the received buffer does not match the expected buffer, VuGen sends a message to the output indicating the mismatch and continues with script execution.
If the socket's type is TCP and the remote side has shut down the connection in an orderly way, lrs_receive finishes without returning any data. If the connection was aborted, lrs_receive returns one of the Windows Sockets error codes.
This function is recorded during a Windows Socket session.