Trigger condition of various events in WSAAsynselect () model in Winsock2

xiaoxiao2021-03-06  59

The key to using the wsaasynselect () model is to figure out the trigger conditions of the various events, otherwise it will cause read or write data. The trigger conditions of these events are equally applicable to casyncsocket ================================= [1] fd_read event trigger condition: 1. After the data arrives in Socket, and Did not trigger fd_read (which is the starting phase) 2. After the data arrives at Socket, and the previous RECV () is called 3. After calling the RECV (), the buffer has not read data.

The third point is as follows: 1.100 Bytes data arrive, Winsock2 issues fd_read2. Program uses only reads 50 Bytes, there is still 50 Bytes3.winsock2 to continue the fd_read message

Recv () Returns the situation of WSAEWOULDBLOCK: 1. Data arrive, fd_read trigger, the message joins the program of the program. The program call RECV () will return WSAEWOULDBLOCK (because the data is RECV () before this)

Note: 1.Winsock2 issued a fd_read, if the program does not use RECV (), even if there is that the data does not receive fd_read, another fd_read will not trigger another fd_read, and FD_READ will be sent after the RECV () is called. 2. Situations for multiple recv () for a fd_read: If the program is multi-time RECV () will cause a plurality of empty fd_read, the program turns off fd_read before the second RECV () (you can use WSAAsYNSelect turns off fd_read, then repeate RECV (). 3.Recv () Returns a message such as WSAECONNABORTED, WSAECONNRESET ... and other messages, you can wait until the fd_close event triggered again.

===================== [2] fd_accept event trigger condition: 1. As a request to establish a connection, and never trigger fd_accept (that is, the starting stage) 2. When there is a request to establish a connection, and the previous ACCEPT () is called

Note: After fd_accept triggered, if the program does not call accept (), even if there is a request FD_ACCEPT to establish a connection, it is not triggered, and it is adjusted until the Accept () is called.

================================= [3] fd_write event trigger condition: 1. After connect () or accept () (ie after the connection is established) ) 2. Call send () Return WSAEWOULDBLOCK, and until the send buffer is ready (empty)

Note: When you call Send () when you call WSAEWOULDBLOCK, if the buffer is ready, FD_WRITE is not triggered.

================================= [4] fd_close event trigger condition: you or the peer interrupt connection Note: CloseSocket () FD_CLOSE does not trigger ================================== [5] fd_connect event trigger condition: Circuit () is called, and the connection is established.

Detailed reference MSDN

转载请注明原文地址:https://www.9cbs.com/read-113667.html

New Post(0)