Add support for login and institution keepalive values; Clean up kids in non-mux...
authorMike Rylander <mrylander@gmail.com>
Wed, 20 Aug 2014 00:19:51 +0000 (20:19 -0400)
committerMike Rylander <mrylander@gmail.com>
Wed, 20 Aug 2014 00:19:51 +0000 (20:19 -0400)
Signed-off-by: Mike Rylander <mrylander@gmail.com>
SIPServer.pm

index fdd2152..d16eec3 100755 (executable)
@@ -273,20 +273,24 @@ sub check_pending_connections {
 }
 
 sub sig_chld {
-    for (keys(%kid_hash)) {
-        if ( my $reaped = waitpid($_, WNOHANG) > 0 ) {
-            syslog('LOG_DEBUG', "Reaping child $_");
-            # Mourning... done.
-            $kid_count--;
-            # note: in some cases (when the primary connection is severed),
-            # the active connection is cleaned up in mux_close.  
-            if ($active_connections{$kid_hash{$_}}) {
-                if ($active_connections{$kid_hash{$_}}{worker_pipe}) {
-                    syslog('LOG_DEBUG', "Closing worker pipe after timeout for: $kid_hash{$_}");
-                    delete $active_connections{$kid_hash{$_}}{worker_pipe};
+    if ( !scalar(keys(%kid_hash))) { # not using mux mode
+        1 while waitpid(-1, WNOHANG) > 0;
+    } else {
+        for (keys(%kid_hash)) {
+            if ( my $reaped = waitpid($_, WNOHANG) > 0 ) {
+                syslog('LOG_DEBUG', "Reaping child $_");
+                # Mourning... done.
+                $kid_count--;
+                # note: in some cases (when the primary connection is severed),
+                # the active connection is cleaned up in mux_close.  
+                if ($active_connections{$kid_hash{$_}}) {
+                    if ($active_connections{$kid_hash{$_}}{worker_pipe}) {
+                        syslog('LOG_DEBUG', "Closing worker pipe after timeout for: $kid_hash{$_}");
+                        delete $active_connections{$kid_hash{$_}}{worker_pipe};
+                    }
                 }
+                delete $kid_hash{$_};
             }
-            delete $kid_hash{$_};
         }
     }
 }
@@ -429,7 +433,12 @@ sub mux_input {
                 $self->{login_complete}->(0) unless $self->{login_complete_called};
             }
 
-            $self->sip_protocol_loop($active_connections{$conn_id}{worker_pipe}, $worker_keepalive);
+            $self->sip_protocol_loop(
+                $active_connections{$conn_id}{worker_pipe},
+                $self->{account}->{'worker-keepalive'}
+                    // $self->{institution}->{'worker-keepalive'}
+                    // $worker_keepalive
+            );
 
             exit(0);
 
@@ -485,7 +494,13 @@ sub mux_input {
                     exit(0);
                 }
         
-                $self->sip_protocol_loop($active_connections{$conn_id}{worker_pipe}, $worker_keepalive);
+                $self->sip_protocol_loop(
+                    $active_connections{$conn_id}{worker_pipe},
+                    $self->{account}->{'worker-keepalive'}
+                        // $self->{institution}->{'worker-keepalive'}
+                        // $worker_keepalive
+                );
+
        
                 exit(0);