views:

137

answers:

1

Are SendAsync and ReceiveAsync using IO completion ports?

+2  A: 

Well, IO completion ports work by pending the completion routine as an APC to a worker thread in your ThreadPool (SocketAsyncEventArgsPool). So, the context is some worker thread that was created.

As to your actual question, I can't imagine that they would use anything other than I/O completion ports, it would be very inefficient otherwise; however that is mostly an implementation detail - regardless of how they do it, the reality is that the notification is in an arbitrary context (i.e. you know nothing about what thread you're in), so you need to do things in a thread-safe manner in your completion routine.

For good scalability, I would also try to minimize the work done in this routine, complete the I/O as fast as possible - if you have to do other work, use a separate thread pool that you can queue the real computation on.

Paul Betts
Excellent, thank you.The reason I was asking was that under XP and win32 (the last environment under which I was developing) IO completion port routines executed on the thread that initiated the asynchronous IO (and therefore had to be altertable).I've got a situation now where I have a ReceiveAsync and in the complete routine for that I start another ReceiveAsync.I was worried that if it worked the same as IOCP under XP any chain of ReceiveAsyncs would always execute in the context of the same thread (the one that started it all).
Captain NedD