在 2020年3月21日 +0800 PM8:10,Robert Pluim <address@hidden>,写道:
On Sat, 21 Mar 2020 11:01:05 +0800, HaiJun Zhang <address@hidden> said:
HaiJun> For example, I have binary message format like this:
HaiJun> 1. It has a four-bytes header and payload.
HaiJun> 2. The four-bytes header is the payload size of the message.
HaiJun> First I want to set the size of the recv buffer to 4. After the four
HaiJun> bytes arrived, I parse them and get the size of the payload. Then I
HaiJun> set the size of the recv buffer to the size of the payload to recv the
HaiJun> payload.
Why bother? Youʼre going to have to handle partial recv for the
payload anyway, so you might as well do it from the start.
Robert
I want to do flow control, because too many data may cause UI unresponsive. Set the recv buffer size to 4, and if I don’t fetch the four bytes, please don’t receive more data. If the size (In the four bytes header) is too big, ask the user if the message should be received.