Re: Network buffering question
- From: "Alex Fraser" <me@xxxxxxxxxxx>
- Date: Tue, 29 Aug 2006 22:37:38 +0100
"Till Crueger" <TillFC@xxxxxxx> wrote in message
news:pan.2006.08.28.22.18.25.590148@xxxxxxxxxx
[snip]
I am working on some network code right now. For help I am using "Beej's
Guide to Network Programming". Now I stumbled upon the chapter about data
encapsulation. I get the point that you should send across the Network
some information about how much data you have been sending, so you can
reconstruct the packets correctely. So far I think I got everything.
However then he says that you need to make your buffer twice as large as a
single packet, because you might actually read past the packet you are
trying to handle at the moment. Since you can tell recv() how much you
want to recieve couldn't you just make sure this wont ever happen?
I cannot see a valid reason for the buffer being "twice as large as a single
packet". However, an "oversized" buffer is a good thing up to a point.
You can make sure you don't read past a message if you know how long the
message is in advance, but that is often not the case. Many protocols use a
delimiter to separate messages, for instance the sequence CR, LF.
I would
have tried something like this:
read size information
check if everything was recieved
read the rest (let recv() know how much to read)
Or is there some problem to this, so you actually need to use bigger
buffers or circular buffers?
Thanks for your help,
Till
--
Please add "Salt and Pepper" to the subject line to bypass my spam filter
.
- References:
- Network buffering question
- From: Till Crueger
- Network buffering question
- Prev by Date: Re: Code Comprehension
- Next by Date: Re: C++ dynamic structures
- Previous by thread: Re: Network buffering question
- Next by thread: Re: Network buffering question
- Index(es):
Relevant Pages
|