title: Is it necessary to set hEvent on the OVERLAPPED structure when doing I/O completion ports?
body: <p>I'm using I/O completion ports on Windows for serial port communication (we will potentially have lots and lots of serial port usage). I've done the usual, creating the IOCP, spinning up the I/O threads, and associating my <code>CreateFile()</code> handle with the IOCP (<code>CreateFile()</code> was called with <code>FILE_FLAG_OVERLAPPED</code>). That's all working fine. I've set the <code>COMMTIMEOUTS</code> all to 0 except <code>ReadIntervalTimeout</code> which is set to <code>MAXDWORD</code> in order to be completely async.</p>
  
  <p>In my I/O thread, I've noticed that <code>GetQueuedCompletionStatus()</code> blocks indefinitely. I'm using an <code>INFINITE</code> timeout. So I put a <code>ReadFile()</code> call right after I associate my handle with the IOCP. Now that causes <code>GetQueuedCompletionStatus()</code> to release immediately for some reason with 0 bytes transferred, but there's no errors (it returns true, GetLastError() reports 0). I obviously want it to block if there's nothing for it to do. If I put another <code>ReadFile()</code> after GetQueuedCompletionStatus(), then another thread in the pool will pick it up with 0 bytes transferred and no errors.</p>
  
  <p>In the examples I've seen and followed, I don't see anyone setting the <code>hEvent</code> on the <code>OVERLAPPED</code> structure when using IOCP. Is that necessary? I don't care to ever block IOCP threads -- so I'll never be interested in <code>CreateEvent(...) | 1</code>.</p>
  
  <p>If it's not necessary, what could be causing the problem? <code>GetQueuedCompletionStatus()</code> needs to block until data arrives on the serial port.</p>
  
  <p>Are there any good IOCP serial port examples out there? I haven't found a complete serial port + IOCP example out there. Most of them are for sockets. In theory, it should work for serial ports, files, sockets, etc.</p>