When you emit e/S asynchronous, completion function or the e/S port endpoint receives, among other things, a pointer to the OVERLAPPED I/o structure was originally issued against. And it is your key to the Golden riches.
If you need to associate information with the e/S operation, there is no obvious to say, place if some people end up doing things like maintaining a master table records all I/O outstanding overlapped as well as related information that i/o. When each I/O completes, they find the e/S in the master table to locate additional information.
But it is easier.
Given that the OVERLAPPED structure is passed by address, you can store your extra information alongside the OVERLAPPED structure:
/ / in Cstruct OVERLAPPEDEX {OVERLAPPED o;} CClient * AssociatedClient; {CLIENTSTATE ClientState;}; / / or c ++ struct OVERLAPPEDEX: OVERLAPPED struct {CClient * AssociatedClient;} {CLIENTSTATE ClientState;} ;When e/S is finished, you can use the macro CONTAINING_RECORD or just static_cast LPOVERLAPPED OVERLAPPEDEX * and bingo, there is some additional information. Of course, you need to know the e/S one issued against a structure OVERLAPPEDEX instead of an ordinary OVERLAPPED structure, but there are ways to keep track of who. If you use an end function, and then just use a completion function OVERLAPPEDEX-aware when the OVERLAPPED structure is part of a structure OVERLAPPEDEX. If you use an I/O completion port, you can use the key end or to distinguish boring OVERLAPPED I/O for OVERLAPPEDEX e/S asynchronous OVERLAPPED.hEvent.
No comments:
Post a Comment