Quote:
When does a timer set itself to false? Does it set enabled to false before the timeout function is run or after the timeout function is run?
Have to look at the code for the timer itself to determine that. A OneShot timer sets enabled=false, before calling the TimeOut event override. A Periodic timer never automatically sets enabled to false.
Quote:
What happens if a timer is already enabled and a call gets made to set enable = true? Does the time reset (i.e. back to 2s) or does the time keep running down?
Setting enabled=true will reset the timer back to its original interval.
Quote:
The reason we need to handle timeouts quicker than TCP is we have quick communications. Everything is local. No response in 2s means we try again as the data is small and in reality communication is happening with 500ms.
The trick with doing this is knowing when you can recycle the underlying TCP connection. If you simply call CloseConnection on the httpclientv2 object, one of two things can happen. If a connection is pending (i.e. the TCP connection has started but not completed), the HTTPClientV2 will throw and exception and continue in the pending connection state. If the connection has been established, then we will perform an active TCP close and the object will reset its internal state.
Normally the server will perform the active close on the HTTP TCP connection. In fact, that active close is what triggers the HTTPDataReceived event to occur (although if partial data has been received when you force the close, that event will also occur).
It sounds like you have a pool of objects already. I would recommend at a minimum you structure your pool so that any objects you forcibly cancel go to the bottom of the pool and won't be reallocated for as long as possible. Also be aware that closing TCP connections from your end will cause the underlying firmware level TCP connection to enter a 2MSL state which prevents the connection from being reused for two minutes. As there are only 32 total TCP connections possible this can result in running out of connections for a time if you frequently manually close the connections.