SIP multiplex
authorBill Erickson <berick@esilibrary.com>
Fri, 13 Sep 2013 13:32:44 +0000 (09:32 -0400)
committerBill Erickson <berick@esilibrary.com>
Fri, 13 Sep 2013 13:32:44 +0000 (09:32 -0400)
* remove output_fh tracking.  It's not needed.
* write output Sip::write_msg via POSIX::write to bypass IO::Multiplex
  output buffer caching.  This is needed since SIP child procs never
  return from mux_input (they exit) so the cached output is never
  sent to the client.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
SIPServer.pm
Sip.pm
Sip/MsgType.pm

index e60532e..edc6a21 100644 (file)
@@ -243,7 +243,6 @@ sub mux_input {
     }
 
     $self = $active_connections{$conn_id}->{net_server};
-    $self->{output_fh} = $mux_fh;
 
     my $pid = fork();
     die "Cannot fork: $!" unless (defined($pid) && $pid > -1);
diff --git a/Sip.pm b/Sip.pm
index 07a4cd7..0e184fc 100644 (file)
--- a/Sip.pm
+++ b/Sip.pm
@@ -226,8 +226,6 @@ sub read_SIP_packet {
 sub write_msg {
     my ($self, $msg, $file) = @_;
 
-    $file ||= $self->{output_fh};
-
     if ($error_detection) {
         if (defined($self->{seqno})) {
             $msg .= 'AY' . $self->{seqno};
@@ -236,11 +234,13 @@ sub write_msg {
         $msg .= checksum($msg);
     }
 
+    my $outmsg = "$msg\r";
 
     if ($file) {
-        print $file "$msg\r";
+        print $file $outmsg;
     } else {
-        print "$msg\r";
+        my $rv = POSIX::write(fileno(STDOUT), $outmsg, length($outmsg));
+        syslog("LOG_ERR", "Error writing to STDOUT $!") unless $rv;
     }
 
     syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
index 4648ef4..6fb4793 100644 (file)
@@ -423,7 +423,6 @@ sub handle {
        $req && (substr($msg, 0, 2) ne $req)) {
        return substr($msg, 0, 2);
     }
-    $self->{output_fh} = $server->{output_fh};
     return($self->{handler}->($self, $server));
 }