I'm not sure I understand your code. The only solution I know of to this lies in the Battle.net protocol itself. Consider the packet header:
(INT8) 0xFF
(INT8) Packet ID
(INT16) Packet Length
In this case, we're relying on the packet itself to tell us how much data to read. Consider lines 135 through 147 of
the PacketThread class. It reads the first four bytes, checks for various errors, then establishes the length of the packet we're currently working with. It completely ignores anything left after if it's a clump as you're dealing with, or it waits for the remainder if it hasn't arrived yet, as I mentioned in that quote.
TLDR: It depends on the protocol.