Re: Benefits of CFSocketSendData() over send()
Re: Benefits of CFSocketSendData() over send()
- Subject: Re: Benefits of CFSocketSendData() over send()
- From: Quinn <email@hidden>
- Date: Tue, 7 Oct 2008 09:20:34 +0100
At 3:42 +0800 7/10/08, Liwei wrote:
I feel tempted to use send() but the idea of using a CoreFoundation
replacement sounds OS-friendly.
There's really no need to favour CFSocketSendData over the various
low-level socket calls. CFSocket is designed to work in concert with
BSD-level sockets. You can mix and match CFSocket and BSD-level
calls (more or less) at will.
However, I can't seem to find any documentation on precisely how
CFSocketSendData() works.
CFSocketSendData is based on <x-man-page://2/send> or
<x-man-page://2/sendto>, depending on whether you supply an address.
As such, it inherits the characteristics of those routines.
I need to know the following:
1. How much data can I send each time?
That depends on the underlying protocol. Earlier you stated that
you're using UDP. In that case the maximum UDP packet size is
(around) 64 KB.
2. Can I just throw in a big chunk without knowing the MTU of the network?
Yes. If you send a large UDP packet it will get fragmented into
MTU-sized chunks. That's generally less than ideal.
3. What happens when the network is busy and cannot send all the data?
It drops one of the fragments. This will result in the entire UDP
packet not making it to the far end.
4. Does a timeout of 0 mean the send occurs in the background?
No.
The timeout is converted to a (struct timeval) and applied to the
socket via SO_SNDTIMEO. That socket option is described in
<x-man-page://2/getsockopt>.
5. Would I be able to tell how much data has been sent?
For a datagram based socket like UDP, send and sendto are an
all-or-nothing proposition. That is, the socket will either accept
the entire datagram (with no error) or none of it (and you get an
error).
Also, is there a nice function to tell if a socket is available for
sending other than using select() and callbacks?
There are numerous (select, poll, kqueues, CFSocket). The best to
use depends on the main loop of your program. If you're program's
main loop is runloop based, CFSocket is the best choice.
* * *
btw Lots of CF is available as part of the Darwin open source
project. So if you want to know what CFSocketSendData does, you can
look at the source.
<http://www.opensource.apple.com/darwinsource/10.4/CF-368/RunLoop.subproj/CFSocket.c>
[This link may require an APSL <http://www.opensource.apple.com/apsl/>
account.]
S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
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