use Net::Server::PreFork;
use Net::Server::Proto;
use IO::Socket::INET;
+use IO::String;
use Socket qw(:crlf);
use Data::Dumper; # For debugging
require UNIVERSAL::require;
+use POSIX qw/:sys_wait_h :errno_h/;
#use Sip qw(readline);
use Sip::Constants qw(:all);
sub REAPER {
for (keys(%kid_hash)) {
- if ( my $reaped = waitpid($_, &WNOHANG) > 0 ) {
+ if ( my $reaped = waitpid($_, WNOHANG) > 0 ) {
# Mourning... done.
$kid_count--;
delete $kid_hash{$_};
}
}
- $SIG{CHLD} = &REAPER();
+ $SIG{CHLD} = sub { REAPER() };
}
my %active_connections;
sub mux_input {
my $mself = shift;
my $mux = shift;
- my $fh = shift;
+ my $mux_fh = shift;
+ my $str_ref = shift;
+
+ # clone the mux string into a file handle
+ my $str_fh = IO::String->new(''.$$str_ref);
+
+ # clear read data from the mux string ref
+ $$str_ref = '';
my $self;
- my $conn_id = fileno($fh);
+ my $conn_id = fileno($mux_fh);
# check for kids that went away
REAPER();
return;
}
- &$transport($self, $fh);
+ &$transport($self, $str_fh);
$active_connections{$conn_id} =
{ id => $conn_id,
}
$self = $active_connections{$conn_id}->{net_server};
+ $self->{output_fh} = $mux_fh;
my $pid = fork();
die "Cannot fork: $!" unless (defined($pid) && $pid > -1);
# build the connection we deleted after logging in
$self->{ils} = $active_connections{$conn_id}->{ils}->new($self->{institution}, $self->{account});
- my $input = Sip::read_SIP_packet($fh);
+ # build the connection we deleted after logging in
+ my $input = Sip::read_SIP_packet($str_fh);
$input =~ s/[\r\n]+$//sm; # Strip off any trailing line ends
my $status = Sip::MsgType::handle($input, $self, '');
sub raw_transport {
my $self = shift;
- my $fh ||= *STDIN;
+ my $fh = shift || *STDIN;
+
my ($uid, $pwd);
my $input;
my $service = $self->{service};
syslog("LOG_DEBUG", "raw_transport: uname/inst: '%s/%s'",
$self->{account}->{id},
$self->{account}->{institution});
-
}
sub telnet_transport {
my $self = shift;
- my $fh ||= *STDIN;
+ my $fh = shift || *STDIN;
+
my ($uid, $pwd);
my $strikes = 3;
my $account = undef;
sub write_msg {
my ($self, $msg, $file) = @_;
+ $file ||= $self->{output_fh};
+
if ($error_detection) {
if (defined($self->{seqno})) {
$msg .= 'AY' . $self->{seqno};
print $file "$msg\r";
} else {
print "$msg\r";
- syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
}
+ syslog("LOG_INFO", "OUTPUT MSG: '$msg'");
$last_response = $msg;
}