Recv Considered Harmful

In standard socket programming, the 'recv()' function is used to obtain data from a stream. With TCP/IP, a result of recv'ing the packet is that the TCP/IP connection window size increases, allowing more data to be sent. On embedded devices this style of programming can be harmful. Using recv with the MSG_PEEK flag should leave the data in the input buffer, which I assume means that the TCP window remains the same size. You would of course have to remember to recv again without the peek flag when your processing is done.

recv() makes socket code more messy than it could be. An alternative interface that allows you to decouple the copying and the flow control mechanism from reading the incoming stream can lead to better code.


What's an acceptable alternative to recv() in this context?

Use something other than the low-level Berkeley C socket libraries.

POSIX Async IO should be able to use user-provided input/output buffers for zero-copy I/O (although, implementations might just map AIO over the berkeley interfaces anyway...)


Hmm, I thought this page might be about how it is relatively simple to write the rest of the letters in the word "receive". ... But then you wouldn't be able to smugly align you recv and send calls!


CategoryConsideredHarmful


EditText of this page (last edited June 2, 2005) or FindPage with title or text search