Skip to main content
GameDev.net gamedev.net
🔒 Locked

winsocket overlapped i/o question

Started by howie_007 Oct 25, 2012 at 1:58 PM 3 replies 1.6k views
Original Post
howie_007
howie_007
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?
clb
clb
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.
howie_007
howie_007
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"?
hplus0603
hplus0603
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.
enum Bool { True, False, FileNotFound };
howie_007
howie_007
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.