Difference between revisions of "FAQ.Timeout"

From Overbyte
Jump to navigation Jump to search
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
[[Main_Page | Main page]] -> [[FAQ]] -> [[Timeout]]
+
[[Main_Page | Main page]] -> [[FAQ]] -> [[FAQ.Timeout | Timeout]]
  
== Implementing a timeout ==
+
== Implementing a Timeout ==
  
 
Implementing a timeout with async socket is just a matter of testing since how long you haven't received a read request (OnDataAvailable event) from the remote site, or a write request (OnSendData), or a connect status (OnSessionConnected), or a disconnect status (OnSessionClosed) and so on.
 
Implementing a timeout with async socket is just a matter of testing since how long you haven't received a read request (OnDataAvailable event) from the remote site, or a write request (OnSendData), or a connect status (OnSessionConnected), or a disconnect status (OnSessionClosed) and so on.

Latest revision as of 17:13, 3 March 2006

Main page -> FAQ -> Timeout

Implementing a Timeout

Implementing a timeout with async socket is just a matter of testing since how long you haven't received a read request (OnDataAvailable event) from the remote site, or a write request (OnSendData), or a connect status (OnSessionConnected), or a disconnect status (OnSessionClosed) and so on.

It is easy to implement timeouts at the application level using a simple and single TTimer for all timeouts. The idea is to have a list of timeout structures (to be created). This structure could be the time the last activity happened and a callback (a kind of event) to be called when the timeout occur. Of course each structure has to be updated each time some activity occurs.

When the timer event is triggered, you scan the list to see the items having no activity since a given timeout, and then call their callback. From hte callback you do whatever action is needed, for example closing the connection.