Re: Does CFWriteStream coalesce writes?
Re: Does CFWriteStream coalesce writes?
- Subject: Re: Does CFWriteStream coalesce writes?
- From: Josh Graessley <email@hidden>
- Date: Thu, 29 May 2008 12:21:45 -0700
On May 29, 2008, at 11:57 AM, Jens Alfke wrote:
On 29 May '08, at 11:36 AM, Mark Pauley wrote:
Nope, we don't buffer in CFSocketStreamWrite. You might want to
take a look at a tcp dump to see just how many bytes per packet
you're sending... I would imagine this is a place where we could
improve, (signalling canAcceptBytes is probably expensive, as is
sending short packets).
Thanks. The issue is that the data to be sent is spread out in
multiple locations: I'm multiplexing segments of messages together,
each message is in its own buffer, and each segment has to be
prefixed with a short header. I don't want to have to copy
everything into a single buffer and then make one -write: call.
But if I make multiple write calls in a row, subsequent ones will
block if the stream runs out of write space. (Is that a bug?) It
seems I'd have to call -hasSpaceAvailable before each call, to
preflight.
The ideal call to use would be writev. I'm not sure whether it's
safe to combine this with CFStream, however. I know how to extract
the file descriptor from the stream, but if I write directly to it
am I liable to confuse the stream's internal state?
Skip CFStream, jump straight in to CFSocket. It's not scary. Really.
CFSocket will give you a run loop event source and let you interact
directly with the socket. You can use sendmsg to perform a single send
from lots of small buffers. In addition, the socket APIs will always
return EWOULDBLOCK instead of blocking if you put the socket in non-
blocking mode.
-josh
_______________________________________________
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