'Can I use a file handles in IO completion ports with and without overlapped I/O

I want to use ReadFile() (overlapped) on a named pipe in message mode in combination with an I/O completion port.

So, I have multiple threads waiting for ReadFile() to receive data. The awaken thread will process the message and may call WriteFile() on another pipe handle without overlapped I/O.

I only have real small chunks. Is it possible to use a handle that is associated to an I/O completion port with WriteFile() and non-overlapped I/O?

Are there any issues that I should be aware of?



Solution 1:[1]

Is it possible to use a handle that is associated to an I/O completion port with WriteFile() and non-overlapped I/O?

no, this not possible. if handle associated to an I/O completion - this file handle opened with the FILE_FLAG_OVERLAPPED flag, and as result overlapped (asynchronous) I/O will be used for this file. maximum what you can do - prevent completion port notification. This is done by specifying a valid event handle for the hEvent member of the OVERLAPPED structure, and setting its low-order bit. A valid event handle whose low-order bit is set keeps I/O completion from being queued to the completion port. but I/O anyway will be asynchronous and in this case.

But I don't want a new message to arrive and handled between receiving and writing. So as long as I start a new Read (overlapped) and I Write the answer (non overlapped) my processes are in a "stable stage".

new message not arive until you not start new Read. so when read complete - first decide - are you need answer to message and if yes - do WriteFile - asynchronous - this not create any problem and you not need wait in place until write completed. and then start new Read.

so really you not need synchronous write on file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RbMm