Re: Regarding CFRunLoop and multible outgoing connections
Re: Regarding CFRunLoop and multible outgoing connections
- Subject: Re: Regarding CFRunLoop and multible outgoing connections
- From: Quinn <email@hidden>
- Date: Fri, 31 Mar 2006 11:13:32 +0100
At 1:56 +0200 31/3/06, Fredrik H. Larsen wrote:
As a previous select() user with while(1){...} implemented, I'm
struggeling using CFRunLoop and multible outgoing connections.
What would you say is the best way to go around this?
What CF APIs are you using? The answer differs depending on whether
you're using CFSocket, or one of the CFStream-style APIs.
o For CFSocket, you can create the socket either unconnected
(CFSocketCreate, CFSocketCreateWithNative,
CFSocketCreateWithSocketSignature) or connected
(CFSocketCreateConnectedToSocketSignature). You can then create a
runloop source (CFSocketCreateRunLoopSource) and add that to your
runloop (CFRunLoopAddSource). For an unconnected socket, you can
then connect it to an address (CFSocketConnectToAddress). You will
then get events as the state of the socket changes. The
kCFSocketConnectCallBack is delivered as the socket connects.
o For CFStream, you can create the stream using various
protocol-specific APIs (CFStreamCreatePairWithSocketToHost for
vanilla TCP, CFReadStreamCreateForHTTPRequest for HTTP, and so on),
then schedule the stream with your runloop
(CFReadStreamScheduleWithRunLoop). You trigger a connect by opening
the stream (CFReadStreamOpen). You will then get events as the state
of the stream changes. For example, kCFStreamEventOpenCompleted is
delivered when the connect is complete.
Share and Enjoy
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, 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