Re: Using CFSocket to connect
Re: Using CFSocket to connect
- Subject: Re: Using CFSocket to connect
- From: Becky Willrich <email@hidden>
- Date: Tue, 2 Jul 2002 10:20:32 -0700
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....)
On Monday, July 1, 2002, at 04:11 PM, Mike Laster wrote:
How do I connect with a timeout in the CFSocket world?
I'm trying to get functionality to connect to a given host:port
successfully
in <= 1 second or give up. The default connect() behavior will wait
up to 2
minutes before returning a failure, which introduces unacceptable
delays.
I currently use select() with a short timeout on a non-blocking socket.
This works, but it leaves me blocking inside of a select() call
instead of
inside of a CFRunLoop like I would like.
_______________________________________________
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.
_______________________________________________
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.