3

I am not sure what approach I should take when dealing with data associated with each socket. Should I use the completion key or should I extend the OVERLAPPED structure.

Extending the OVERLAPPED structure seems like a hack, so does it offer any advantages over the completion key?

1 Answers1

4

The completion key is "per connection" data, that is it is the same on every completion for all operations on a given handle and is a good way to link to a "file" or "socket" structure.

The Overlapped is "per operation" data, each concurrent operation on a handle MUST use a unique overlapped structure. This makes it ideal to hold per operation data such as "type of operation" and associated memory (such as buffers), etc.

The "extended overlapped" isn't a hack, it's the way the design is supposed to be used.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
  • I'm trying to find per operation identifier such as a request context in windows OVERLAPPED or related API call. But I do not find it until I got that we could extend it. But I think this is a hack approach. Thanks for your answer to tell us this usage is common and properly. – LauZyHou Sep 07 '22 at 04:43
  • I guess the alternative would be to allow a ULONG_PTR sized "opaque user data" item in the overlapped structure. That would be a bit more explicit but would force all users of the overlapped structure to spend "pointer size" more bytes of memory on each use... – Len Holgate Sep 07 '22 at 10:47