LP#1042850 fail gracefully without Socket::Linux user/berick/lp-1042850-keepalives-signoff
authorBill Erickson <berick@esilibrary.com>
Thu, 7 Aug 2014 18:07:17 +0000 (14:07 -0400)
committerBill Erickson <berick@esilibrary.com>
Thu, 7 Aug 2014 19:02:39 +0000 (15:02 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
SIPServer.pm

index fa78be9..1aba170 100755 (executable)
@@ -113,13 +113,18 @@ sub process_request {
     my ($sockaddr, $port, $proto);
     my $transport;
 
-    eval { # If it fails ... oh well
-        use Socket::Linux qw(TCP_KEEPINTVL TCP_KEEPIDLE TCP_KEEPCNT);
-        setsockopt($self->{server}->{client}, SOL_SOCKET, SO_KEEPALIVE, 1);
-        setsockopt($self->{server}->{client}, IPPROTO_TCP, TCP_KEEPALIVE, 1);
-        setsockopt($self->{server}->{client}, IPPROTO_TCP, TCP_KEEPIDLE, 120);
-        setsockopt($self->{server}->{client}, IPPROTO_TCP, TCP_KEEPINTVL, 10);
-    };
+    # This is kind of kinky, but allows us to avoid requiring Socket::Linux.
+    # A simple "Socket::Linux"->use won't suffice since we need access to
+    # all of it's bareword constants as well.
+    eval <<'    EVAL';
+    use Socket::Linux qw(TCP_KEEPINTVL TCP_KEEPIDLE TCP_KEEPCNT);
+    setsockopt($self->{server}->{client}, SOL_SOCKET,  SO_KEEPALIVE, 1);
+    setsockopt($self->{server}->{client}, IPPROTO_TCP, TCP_KEEPIDLE, 120);
+    setsockopt($self->{server}->{client}, IPPROTO_TCP, TCP_KEEPINTVL, 10);
+    EVAL
+
+    syslog('LOG_DEBUG', 
+        "Consider installing Socket::Linux for TCP keepalive: $@") if $@;
 
     $self->{account} = undef; # New connection, no need to keep login info
     $self->{config} = $config;