[muscle] Re: timing out a connection attempt
- From: "Jeremy Friesner" <jaf@xxxxxxxxxxxx>
- To: "David Svanberg" <ds@xxxxxxxxxxx>
- Date: Wed, 15 Oct 2003 09:08:42 PDT (-0700)
> How should I handle connection timeouts=3F
>
> When I use the MessageTransceiverThread's AddNewConnectSession method in my
> client it hangs when it can't connect to the server.
Do you mean that the AddNewConnectSession() method doesn't return, or that it
does return but you don't get any connection-completed or connection-failed
events=3F
(I'll assume the latter below)
> There would be nice to have a timeout possibility in the
> AddNewConnectSession method call, i.e. the last argument is a "number of
> milliseconds before this connection attempt is considered timed out". What
> do you guys think=3F Or is there another way to achieve the same effect=3F
As Monni mentioned, the easiest way is to set a timer, and if the timer times
out
before you get a connected-event, you can Reset() the MessageTransceiverThread
and get rid of it. Qt's QTimer class works well for this, or if you aren't
using Qt,
you could obtain a similar effect by subclassing ThreadWorkerSession and
overridding
GetPulseTime(), Pulse() and AsyncConnectCompleted() to cause the session to
self-destruct if too much time passes before the connect succeeds.
Jeremy
- References:
- [muscle] timing out a connection attempt
- From: David Svanberg
Other related posts:
- » [muscle] timing out a connection attempt
- » [muscle] Re: timing out a connection attempt
- » [muscle] Re: timing out a connection attempt
- [muscle] timing out a connection attempt
- From: David Svanberg