5). Overlapped I/O mode (overlapped)
Common functions:
1.WSASocket: Creating sockets
2.TCP
WSASend
WSARecv
3.UDP:
WSASendTo
WSARecvFrom
4.AccepEx (Mswsock.lib Library Export)
WSAIoctl
5. Data type
Wsaoverlapped (wsaoverlapped)
Function: WSAGetOverlappedResult
use:
Buffer Object
typedefstruct_buffer_obj{OVERLAPPED ol;//Overlapping structure Char*buff;buffers used by//Send/recv/acceptex intNlen;//The length of the buffPsocket_obj Psocket;///This I/O belongs to the set of section Word Objects intNoperation;//Type of action submitted #Define op_accept 1 #define op_read 2 #Define op_write 3SOCKET saccept;//Used to save AcceptEx accepted customer section words (only for the listening section Word)_buffer_obj *pnext;} Buffer_obj, *pbuffer_obj;
1. Defining Global Data
HANDLE G_events[wsa_maximum_wait_events]; Array of I/O event handles
int g_nbuffercount; Number of valid handles on the array
Pbuffer_obj G_pbufferhead, G_pbuffertail; The address of a table that consists of a record buffer object
2. Application Buffer
Pbuffer_obj getbufferobj (psocket_obj psocket, ULONG nlen)
3. Releasing buffers
void Freebufferobj (Pbuffer_obj pbuffer)
4. Based on the handle of the trusted event object, find the corresponding buffer_obj
Pbuffer_obj findbufferobj (HANDLE hevent)
5. Update event handle array g_events
void Rebuildarray ()
6. Receive Send
The Buffer_obj object that receives the connection. Function used: postaccept
The Buffer_obj object that receives the data. Function used: POSTRECV
The Buffer_obj object that sends the data. Function used: Postsend
Implementation steps:
1. Set the I/O type to increase the overlap I/O count on the nested word
2. Post this overlapped I/O
After the 7.I/O request is complete, the function that handles it is HANDLEI/O
8.main main function
A) Create a listener socket. Post Monitoring i/0
b) Cyclic processing of i/0 events
Collation from (Windows Networking and communication programming, Wang Yanping)
Code Address: http://download.csdn.net/detail/zhaoyc_59211/192329
Windows Network Programming (2)--Overlapping i/0 models