From 37e8e8e185466fe7cff396a5ed4e4beaf80320ae Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Tue, 28 Aug 2012 12:50:47 -0400 Subject: [PATCH] Timeout in protocol loop To (hopefully) prevent dead connections from hanging around. Signed-off-by: Thomas Berezansky --- SIPServer.pm | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 SIPServer.pm diff --git a/SIPServer.pm b/SIPServer.pm old mode 100644 new mode 100755 index 36f505d..f34afa6 --- a/SIPServer.pm +++ b/SIPServer.pm @@ -262,6 +262,7 @@ sub sip_protocol_loop { my $service = $self->{service}; my $config = $self->{config}; my $input; + my $timeout = $self->{service}->{timeout} || $config->{timeout} || 0; # Now that the terminal has logged in, the first message # we recieve must be an SC_STATUS message. But it might be @@ -279,7 +280,9 @@ sub sip_protocol_loop { #$expect = SC_STATUS; $expect = ''; + alarm $timeout; # First loop timeout while ( $input = Sip::read_SIP_packet(*STDIN) ) { + alarm 0; # Don't timeout while we are processing $input =~ s/[\r\n]+$//sm; # Strip off any trailing line ends my $status = Sip::MsgType::handle($input, $self, $expect); @@ -297,5 +300,6 @@ sub sip_protocol_loop { # We successfully received and processed what we were expecting $expect = ''; + alarm $timeout; # Next loop timeout } } -- 2.11.0