Re: Using CFSocket to connect
Re: Using CFSocket to connect
- Subject: Re: Using CFSocket to connect
- From: Mike Laster <email@hidden>
- Date: Tue, 02 Jul 2002 13:57:44 -0400
On 7/2/02 1:20 PM, "Becky Willrich" <email@hidden> wrote:
>
First, make sure to register for the connection callback on the
>
CFSocket. Then call CFSocketConnectToAddress with a timeout of -1.
>
Now the socket will connect in the background, giving you the
>
connection callback via the run loop when that occurs. There's no way
>
to configure the socket directly to timeout the connect, but it's
>
pretty straightforward to add a CFRunLoopTimer at the same time you
>
call CFSocketConnectToAddress; create the timer to fire at the desired
>
timeout time and add it to the same run loops and modes that the
>
CFSocket is installed on. If the socket connects first, invalidate and
>
discard the timer. If the timer fires first, invalidate and discard
>
the socket.
>
>
REW
>
>
P.S. You know CFStream will do all of this for you, don't you? :)
>
(It won't do the timeout either, but you can do the same timer trick
>
and close the stream....)
Does the fact that I need to explicitly create my own timer mean that the
timeout argument is ignored in the current implementation?
The problem I'm trying to solve is how to provide transparent failover
services. A client has a list of server:port pairs which provide a given
service. What I do is try to connect to #0. If that connection fails (or
dies at some later point), it automatically fails over to server #1, then
#2, etc. The problem I originally ran into was that if the host was
entirely down for server #0, it would take 2 minutes before the TCP/IP stack
would realize this fact, which would defeat the purpose of failing over.
I haven't worked myself up to CFStreams yet. I'm still working on migrating
my threads-and-bsdsockets code into the CF world. I've been wanting to
migrate away from my custom network code forever, since the thread
interaction issues are a nightmare to debug. However, there has never been
an API until CFSocket that I could move to.
How efficient are CFStreams with large streams? I have a distribution
architecture that moves about 400MB/day around multiple machines. This
seems like it could be ideal if it can handle it quickly and without undo
memory or CPU load.
When is this stuff going to be documented anyway? :-)
_______________________________________________
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.