• Advertisement
Sign in to follow this  

winsocket overlapped i/o question

This topic is 1916 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

With the the overlapped i/o model, do you still need parse the received data because what is received can be a partial or a mixture of multiple sends?

Share this post


Link to post
Share on other sites
Advertisement
Yes, overlapped io doesn't buffer up received TCP data any differently than using send()/recv() and you still need to be prepared to receive data in fragments or larger units.

Share this post


Link to post
Share on other sites
I read the overlapped io model is the most efficient but I'm not sure why. Is it because the send and receive can happen at the same time? Hence the name "overlapped"?

Share this post


Link to post
Share on other sites
Overlapped I/O is most efficient because it uses the least system call overhead (and least number of overall system calls) per network stream/data unit transferred. Unless you have > 50 connections running at the same time, it's pretty hard to even measure the difference, though, and the programming model is a lot harder, so for smaller games, I highly recommend using select() in the main thread.

If you need to go overlapped, a good wrapper is boost::asio, which uses overlapped I/O with I/O completion ports on Windows, and kevent/devpoll/whatever-is-best on UNIX flavors.

Also note that the kernel will buffer both outgoing and incoming data. Your call to send() will copy the data you send into the kernel buffer, and then the kernel will take care of sending the data on the network. Your call to recv() will only receive data that is in the kernel buffer. Thus, the regular send()/recv() API also lets you "send and receive at the same time" on the actual wire, assuming your network card is full duplex.

Share this post


Link to post
Share on other sites
Thanks for the info. From what you've said, overlapped send() is a "fire and forget". That's nice because that's one less baby sitting job that needs to be done. Don't think I'd ever need more then 50 connections.

Share this post


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

  • Advertisement