IO Completion Ports and accept()

Started by
2 comments, last by Evil Steve 19 years, 6 months ago
Hi all, I'm trying to make a general purpose server class, and I'm using IO completion ports for it. The server should be able to listen on several ports at once (assume no more than 10 at once), and accept TCP/IP connections. I was hoping that because select() detects that theres a connection pending by saying that theres data to read, that the IOCP would get a read notification when someone tries to connect to one of the listen sockets. But this doesn't happen. So, do I need another thread for accepting connections? And if so, should I have one thread per listen port (as I said, there'll be no more that 10 listen ports), or only one thread and use select() to check if I can accept()? If I have one thread per port, then almost all the time, the threads will be sleeping - although thats another reason to only have one thread... So, ideas? Cheers, Steve
Advertisement
First off, did you associate the listening socket with IOCP?

Kuphryn
Use AccceptEx to post pending Accept and you will receive completion notice if a socket is connected. One thread for all your connect should be enough. Personnaly I'm using 1 thread but I only have 2 port to listen to on my proxy server (one for inter-server communication and the other for communication with "the outside world" (the internet)).

If you look at the way AcceptEx work, you'll see that it can notify you when (an acccept completed) OR (when an accept completed AND the client sent some data). If you choose the later, you should check once in a while if a socket was connected but no data was sent. An example of this, using tcp/ip, can is found in the book "Network programming for microsoft windows" 2nd edition. Also, cbenoit1 has an udp example of a iocp server.

Gizz
Quote:Original post by kuphryn
First off, did you associate the listening socket with IOCP?
Yup.

Gizz: Thanks, I'll have a look at AcceptEx.

This topic is closed to new replies.

Advertisement