Archived

This topic is now archived and is closed to further replies.

kurifu

Dropping a TCP packet

Recommended Posts

With winsocks, if a recv is passed buffer that is not large enough, it will hold onto it data, fill the buffer, and return WSAEMSGSIZE. What is the proper way to drop packets that are larger than expected? Gamedev''s AI Auto-Reply bot.

Share this post


Link to post
Share on other sites
You will _never_ get a WSAEMSGSIZE returned from recv() when using TCP. TCP has no concept of a message or message boundaries. It is a bytestream and nothing else. With UDP you could get a WSAEMSGSIZE in the situation you describe. But generally, it would be easier to just decide on some type of ''maximum'' message size, and always allocate buffers of that size.

Share this post


Link to post
Share on other sites
Don''t take the subject of buffers too lightly....

Ever heard of buffer overruns? You don''t want to have holes in your network code, or someone will develop some kind of nuke, in case they are loosing....

Share this post


Link to post
Share on other sites
No one is taking buffer overruns lightly. The point of the matter is that recv() only returns as much information as you tell it to via the "buffer size" parameter. You will not get a buffer overrun unless you mistakenly pass a value, that is larger than your buffer, to this parameter. Simple.



Dire Wolf
www.digitalfiends.com

Share this post


Link to post
Share on other sites