Question

If I wrote a program that used IO Completion Ports to multiplex using non blocking sockets, how would I know whether the function performed on the socket was send or recv when getQueuedCompletionStatus returned?

Thanks in advance :)

Was it helpful?

Solution

You are receiving a pointer to the OVERLAPPED structure that was used for that operation. Just make another structure that contains the OVERLAPPED structure, so when you get the OVERLAPPED in your completion status you can turn it into your structure:

struct MyOverlapped
{
    OVERLAPPED SystemOverlapped;
    int MyStuff;
    void* MoreStuffForMe;
};

Obviously, you can just just cast the OVERLAPPED* that you receive into a MyOverlapped* to get to your fields. What you put into your fields is up to you.

EDIT: C++ inheritance should work too, so you could also do

 struct MyOverlapped : public OVERLAPPED
 {
     ...
 };

OTHER TIPS

Oh, I don't know. Put a boolean in the buffer structs that are passed in in the initiating ReadFileEx, WriteFileEx calls. Something like that...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top