3 ms·
Oh, now that you mention that I first understand what the correlation between those numbers and malloc is. It wasn't obvious from the article: On top of TCP of
by Matthias247 10y ago
Oh, now that you mention that I first understand what the correlation between those numbers and malloc is. It wasn't obvious from the article:
On top of TCP often length prefixed protocols are used, which means some (e.g. 4) bytes of the length of a "packet" are sent first and the packet is sent afterwards. Thereby you can create the notion of messages and message boundaries on top of the stream oriented TCP.
In the receiver implementation you first have to read the length, then allocate a buffer for the packet and then can read the remaining message into the buffer. If someone will send a HTTP request to such a receiver implementation it will try to allocate the buffer with this number.
The most sensible way to avoid this is checking the first bytes against a maximum message size first. However I have to admit: In my very first implementation of such a protocol I also have not thought about this.