Sign in to follow this  
Evil Steve

IO Completion Ports and accept()

Recommended Posts

Evil Steve    2017
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

Share this post


Link to post
Share on other sites
Gizz    168
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this