1

Most server framework/examples using sockets and I/O completion ports makes notifications in a way I couldn't completely figure out the purpose.

Upon read packets are processed, usually they are reordered to circumvent thread scheduling issues processing packets out of order no matter IOCP ensure a FIFO queue.

The problem is when a socket is closed gracefully or by an error. I saw in both situation, and again by the o.s. thread scheduler, the close notification may be sent to the application (i.e. http server using the framework) "before" the notification of data previously readed.

I think that the close notification should be queued in such way so the application receives it after previous reads.

Is there any intended use in most code I saw or my behavior may be correct depending on the situation?

Mauro H. Leggieri
  • 1,084
  • 11
  • 25

1 Answers1

1

What you suggest makes sense and I would imagine that any code that handles graceful close (a read returning 0 bytes) would do so by processing it after any proceeding successful read. Errors coming out of GetQueuedCompletionStatus(), such as connection reset errors, etc, are harder to integrate into the receive flow as they occur out of band as far as the receive data is concerned. Your question's a bit vague and depends very much on the code you're using and how you (or the people who wrote that code) want to handle these things. There is no single correct way, IMHO.

Len Holgate
  • 21,282
  • 4
  • 45
  • 92
  • Actually I'm doing the base engine for use in an embedded http server but also the same base code will be used for http client requests. But in the past I experienced problems in http client requests, although I received the complete body, most times, the connection was not gracefully closed by the server. In such cases I implemented a workaround so if the error notification is raised in the middle of the readed packets but at the end the body is complete then I ignore the error. – Mauro H. Leggieri Jan 23 '15 at 22:33
  • Thanks @Len. I got new ideas for doing my implementation – Mauro H. Leggieri Jan 26 '15 at 14:00