Jump to content
  • Advertisement
Sign in to follow this  
Evil Steve

IO Completion Ports and accept()

This topic is 5019 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!