Re: Time out a connect() call
Re: Time out a connect() call
- Subject: Re: Time out a connect() call
- From: Josh Graessley <email@hidden>
- Date: Mon, 28 Feb 2011 13:19:23 -0800
Timeouts are arbitrary. Depending on them is dangerous.
If a server is responding slowly or there is a lot of packet loss, that 75 second timeout may just manage to establish a connection where the 5 second timeout would not.
The most common reason people want to use a shorter timeout is that they're performing a blocking connect. Imagine if Safari locked up entirely while it was waiting for a connection to complete. That would be a terrible experience. Instead, Safari uses non-blocking connects and keeps the UI responsive while the connect occurs. This puts the "timeout" in the hands of the user. Safari will still hit the default TCP connection timeout of about 75 seconds. While that connection is being established, the user has the freedom to create new windows or cancel the connection. This gives someone trying to buy concert tickets from an overloaded server a better chance of getting through than the arbitrary 5 second timeout, while still satisfying the insanely impatient (such as myself) that may grow tired of waiting if the connection attempt takes more than 500ms.
There is a socket option that will let you adjust the TCP connection timeout. Changing the timeout does not address the issue that 5 seconds can feel like an eternity, and any timeout short enough to not feel like an eternity is unlikely to be long enough to satisfy every situation.
-josh
On Feb 28, 2011, at 1:10 PM, Nathan Sims wrote:
> Is there some way to 'time out' a connect(2) call? I'm using a TCP/IP socket over an intranet and if I specify an IP address and port that I can't connect to, it takes 75 seconds to time out! If that could be reduced to 5 seconds or so it would be great.
>
> _______________________________________________
> 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
_______________________________________________
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