Advertisement

UDP and MSG_PEEK

Started by March 05, 2005 10:45 PM
1 comment, last by Dravalen 19 years, 11 months ago
I've been messing around a bit with UDP of late, trying to wrap my head around how it works versus TCP, anyway... In my previous TCP applications I would simply use mutltiple calls to recv() to read in the incoming packet in sections. However I've discovered pretty quickly that with Datagram sockets that if I try to read in any less than the full packet size recvfrom() will return WSAMSGSIZE and the rest of the packet in the buffer will be discarded. Now, this wouldn't bug me so much if it didn't have the exact same behavior with MSG_PEEK passed as a flag to recvfrom(). I'm curious to know if there's any way to look at the packet without reading the entire data set in. I know it is possible to use ioctlsocket with FIONREAD to get the amount of data waiting on the socket but it seems a little unwieldly. [Edited by - Dravalen on March 6, 2005 12:22:15 AM]
Why not allocate a fixed 64 kB buffer? That's (slightly more than) the maximum size of an UDP packet. Although it is possible to determine the largest possible size programmatically too, but for some reason wine doesn't seem to emulate those queries.

If you're designing the protocol yourself you should probably set a much lower limit anyway as to not exceed the network's MTU.
Allocating a fixed 1 kB buffer shouldn't be that bad, right?

It's 6 AM so why on earth haven't I got to bed yet? Damn gamedev addiction..
Advertisement
Makes sense, I just did a little poking around and it looks like the minimum MTU is 576 that allows for 512 bytes for payload.

This topic is closed to new replies.

Advertisement