IO Completion Ports and OVERLAPPED management

Edward83

How win32 manages instances of OVERLAPPED struct in context of two functions:

GetQueuedCompletionStatus
PostQueuedCompletionStatus
  1. When I call GetQueuedCompletionStatus does win32 free instance of OVERLAPPED struct or I must do it by my self?

  2. When I send data with PostQueuedCompletionStatus does win32 copy it to internal structs? When I must free memory of sent data?

  3. Where I could find some picture with scheme of processing of OVERLAPPED data between GetQueuedCompletionStatus, PostQueuedCompletionStatus and IOCP queue?

Len Holgate

The OVERLAPPED structure must exist from when a successful I/O operation (or manual PostQueuedCompletionStatus()) executes until the OVERLAPPED emerges from a call to GetQueuedCompletionStatus().

You are responsible for the lifetime of the structure.

You'll see from the MSDN docs that GetQueuedCompletionStatus() actually takes "a pointer to a variable that receives the address of the OVERLAPPED structure that was specified when the completed I/O operation was started.". What you actually get out of that call is a pointer to the original OVERLAPPED that you passed when you made the PostQueuedCompletionStatus() call (or initiated an overlapped I/O operation).

This is all actually very useful as the "normal" way to use the OVERLAPPED structure is to place it inside a larger structure which holds all of the 'per operation' information that you might need - so it's the ideal way to navigate directly from the limited information that you're given when you call GetQueuedCompletionStatus() to, for example, the data buffer that you used in your overlapped read call...

I find the best way to deal with OVERLAPPED structures is to a) embed them in the buffer you're using for read/write b) reference count them and c) return them to a pool for reuse when the ref count drops to 0.

I have some source code that you could download (here) which may make this a little easier to understand (it's a full IOCP server example so it's a little complex, but it works and shows how these things can be used).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Windows: Event-based Overlapped IO vs IO Completion Ports, Real World Performance

WinApi: IO Completion Ports

IO Completion Ports and socket send()

IO Completion Ports and socket WSARecv()

How to reregister for IO Completion ports for a handle

io completion ports issue with calling multiple wsarecv or wsasend per GetQueuedCompletionStatus

Understanding Asynchronous / Overlapped IO

Completion key vs extending the OVERLAPPED structure

Windows overlapped IO actually blocks

Linux and I/O completion ports?

I/O Completion ports C++ And Threadpools

IO Completion port returning NULL Completion Key

AVR IO Ports can not be global

Async IO without completion port?

IO Completion port Linux equivalent

What are IO ports, serial ports and what's the difference between them?

Socket.io listening on multiple ports?

How to dynamically add IO ports to a Chisel Bundle?

AVR Is it possible to address IO ports indirectly

Dont see system.io.ports

How to verify or check I/O (Input / Output, io, IO) ports?

How does the operating system post io completion messages for async io

ASIO IO completion callbacks order vs the order of actual IO operations

Unexpected WSA_IO_PENDING from blocking (with overlapped I/O attribute) Winsock2 calls

Data align when socket recv() then written to file using overlapped_io with FILE_NO_BUFFERING_FLAG

Spring IO platform release management

WSO2 APIM Management: Use standard ports for HTTP and HTTPS

What Linux has BSD-ports like package management?

Access to PIT (?) IO ports 44h and 46h - what do those ports do?