0
votes

I have my own overlapped structure for asynchronous IO using IO Completion ports.

Now i get notification for read / write completions. Can i pass a CALLBACK function as a parameter in the overlapped structure?

This will allow me to specify various callback functions based on the type of overlapped structure i passed

Has anybody had any luck with this?

1
The overlapped structure is almost always extended to include implementation-defined data. I see no reason why you couldn't stuff a callback function pointer in there as well. Note however that GetQueueCompeletionStatus loops are often complex enough, and pushing the underlying data through to a CB may not buy you much (but I can certainly see how it could eliminate a switch or jump-table dereference from the loop). - WhozCraig

1 Answers

4
votes

Create you own structure derived from OVERLAPPED:

struct MyOverlapped : OVERLAPPED
{
  CALLBACK MyCallback;
};

Now use this instead:

MyOverlapped *o=new MyOverlapped;
o->MyCallback=CallbackHandler;

WriteFile(..,..,MyOverlapped);

Then when you get the OVERLAPPED back you can cast it to your derived version:

MyOverlapped *o=static_cast<MyOverlapped*>(overlapped);

And now you can access the callback. I'm guessing you're getting the OVERLAPPED instance back from a call to GetQueuedCompletionStatus where the pointer you get back will actually point to your derived structure.