Windows Network Programming (2)--Overlapping i/0 models

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.