Closed Ali-Nasrolahi closed 2 months ago
Sure!
I have modified the patch based on your requested changes.
Also, I believe the performance decrement is due to the frequency of start/reset
-ing and cancel
-ing the timeout's handler during each read/write operation. Which as you have mentioned, needs to be improved.
Objective
Automatically closing a connection, which becomes stalled for some reason. Fixes MortezaBashsiz/nipovpn#79
Implementation Details
Before every read/write operation, a timer (
deadline_timer
) gets started/reseted, and after each successful I/O; the timer gets cancelled. When timer's handlers called ,in case of an expiration, it closes associated socket with the connection; by doing so, any blocking I/O on respected socket will be interrupted.This patch only addresses TCPConnection and TCPClient classes' read and write methods. The underlying implementation is identical for both classes.
Test
For testing, I did following scenarios while
timeout
is specified:www.google.com
usingcurl
to check to ensure no data transfer issue.telnet
to agent's socket and waiting to be closed by timeout.My tests are not addressing every block of read and write code, therefore this patch should be tested further to ensure stability.
About the diffs
Timeout configuration is identical to
timeWait
and uses similar value range.I have implemented three main method to handle the timer:
resetTimeout
,cancelTimeout
andonTimeout
. And few other minor changes.Please, let me know of any issue/suggestion :)