Re: CFSocket questions
Re: CFSocket questions
- Subject: Re: CFSocket questions
- From: Douglas Davidson <email@hidden>
- Date: Fri, 6 Sep 2002 10:06:15 -0700
On Friday, September 6, 2002, at 09:23 AM, Edward Fink wrote:
1.) I have read that if I use CFSocketConnectToAddress with a timeout
of -1 it will connect in the background. And...If it connects in the
background I can add the callback "kCFSocketConnectCallBack" to my
already existing callback of "kCFSocketDataCallBack". Is this
correct? And if so how is this accomplished?
am using code like the following which adds the Data callback:
CFSocketRef s = CFSocketCreate(NULL, PF_INET, SOCK_STREAM, IPPROTO_TCP,
kCFSocketDataCallBack, whatToDo, NULL);
How do I add the second callback???
Just make that fifth argument (kCFSocketDataCallBack |
kCFSocketConnectCallBack).
2.) Can I reference the native socket directly while using CFSocket?
So for example using the native socket's send(). If so how do I go
about this and is there any benefit/downside to doing this?
Yes, you can definitely reference the native socket directly; you can
obtain it from the CFSocket with CFSocketGetNative(). In fact, there
are many cases in which you must deal with the underlying
socket--CFSocket is not intended to be a complete wrapper around socket
functionality, but rather a way for sockets to serve as run loop
sources. For example, if you want to set socket options, you will need
to use the native socket. It would also be perfectly reasonable to
write to the socket directly using send() and use CFSocket to handle
reads.
What you would want to avoid is interfering with what the CFSocket is
doing with the socket. For example, if you are using
kCFSocketDataCallBack, then CFSocket expects to do the reads from the
socket itself, so you wouldn't want to read at the same time. In all
cases, you would not want to close the socket from under the
CFSocket--you must invalidate the CFSocket first, and at that point if
you have left kCFSocketCloseOnInvalidate set, CFSocket will have closed
the socket; or if you have cleared kCFSocketCloseOnInvalidate, then you
would be free to close the socket yourself when appropriate.
Douglas Davidson
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.