Packet Reading Strategy
I was wondering if peeps could give me an idea about how to read complete/incomplete packets out of a receive buffer.
At the moment, I'm just passing the entire buffer to the validation function, which checks reported size against buffer length, checksum etc. The problem is when the buffer contains a fragment of a packet yet to be fully received, this is currently being discarded as erroneous but obviously that's not good as the peer then has to retransmit, blah blah blah.
I'm having one of my mental block periods at the moment, but would it go something like:-
Read as many valid packets as possible until you come across one that has bad size field
Copy from this point in the buffer back to the start
Read into buffer address + part packet length
do you have a packet length in the packet header?
In this case you can retry reading till you achieve the required number of bytes...
And only then process the decoding