Re: After Autoreleasing Still Getting Leaked
Re: After Autoreleasing Still Getting Leaked
- Subject: Re: After Autoreleasing Still Getting Leaked
- From: Jens Alfke <email@hidden>
- Date: Thu, 16 Jun 2011 12:29:27 -0700
On Jun 15, 2011, at 7:01 PM, Tony Romano wrote:
> TCP does NOT guarantee you will get the WHOLE PACKET on one receive call.
> BEFORE you PROCESS any data, you need to know that you have ALL the data.
> It may work MOST of the TIME, but there are times when it won't and your
> code WILL FAIL.
You’re correct, but your point is a little confusing because you’re using the word “packet” to mean an application-level message. Since ‘packet’ already has a very specific meaning in IP networking, it’s best to use a different word like “message” or “chunk” or “blob” or something.
So to rephrase: Just because you sent a chunk of bytes together in one TCP write, the recipient is not guaranteed to receive the same chunk of bytes in a single read. It’s quite likely that this chunk will be combined with bytes written in other write calls, or split in half across two reads. TCP is taking the data you give it and shoving it into buffers in the kernel, and those buffers get split up and sent out as IP packets according to the kernel’s whim and some complicated windowing algorithms. There’s absolutely no relation between the groups of bytes you write, the IP packets that get sent, and the groups of bytes the client reads.
If I can once again plug my MYNetwork framework <http://bitbucket.org/snej/mynetwork>, it includes a protocol called BLIP that supports sending application-level messages, which can also include metadata (key/value pairs like HTTP headers). It even supports multiplexing multiple messages at the same time, so one huge message won’t clog up the socket and block others till it finishes. This stuff is a pain in the ass to get right and I recommend using someone’s already-tested implementation over writing your own. (Or in other words, “I suffered for my art so you wouldn’t have to” :)
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden