From: Thomas Berezansky Date: Tue, 28 Aug 2012 16:50:47 +0000 (-0400) Subject: Timeout in protocol loop X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=37e8e8e185466fe7cff396a5ed4e4beaf80320ae;p=working%2FSIPServer.git Timeout in protocol loop To (hopefully) prevent dead connections from hanging around. Signed-off-by: Thomas Berezansky --- 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 } }