Does CFWriteStream coalesce writes?
Does CFWriteStream coalesce writes?
- Subject: Does CFWriteStream coalesce writes?
- From: Jens Alfke <email@hidden>
- Date: Thu, 29 May 2008 11:06:42 -0700
My BLIP[1] protocol uses asynchronous NSStreams for TCP I/O. I'm a bit
unsure about the efficiency of the recommended[2] technique for
writing to the stream. Specifically, the examples suggest making _one_
write call per NSStreamEventHasSpaceAvailable notification. This
works, since if there's more space available, the notification will be
sent again, resulting in another write.
My worry: Will this result in CFNetwork making multiple small write
syscalls? If so, if the writes are smaller than the network packet
size (the example uses only 1kbyte) will this result in TCP
inefficiently sending multiple small packets?
Or do my consecutive writes get buffered together by CFNetwork or the
kernel and stuffed into full-size packets? (I'm sure this has
something to do with the TCP Nagle algorithm, but my understanding of
that is fuzzy at best.)
(Some of my writes are as small as 12 bytes, the size of a message
header in my protocol. At first I was calling the stream's write
method multiple times in my event handler, but I found that if the
stream ran out of room the second write could block, even though the
stream is ostensibly in non-blocking mode. So I went back to issuing
only a single write per event.)
—Jens
[1] http://mooseyard.com/projects/MYNetwork/
[2] file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Conceptual/Streams/Articles/WritingOutputStreams.html
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden