Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #577

Merged
merged 2 commits into from
Mar 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions lib/Socket_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ sub new {
my $self = { state => '' };

$port_name = $host_port unless $port_name;
print
"\n\nWarning: duplicate ID codes on different socket_Item objects: id=$id\n\n"
&::print_log ("[Socket_Item] WARNING: duplicate ID codes on different Socket_Item objects: id=$id")
if $id and $socket_item_by_id{$id};
$$self{port_name} = $port_name;
$$self{host_port} = $host_port;
Expand Down Expand Up @@ -141,10 +140,10 @@ sub start {

if ($port) {
if ( $main::Socket_Ports{$port_name}{sock} ) {
&::print_log("Socket already opened for $port_name");
&::print_log ("[Socket_Item] Socket already opened for $port_name");
return $main::Socket_Ports{$port_name}{sock};
}
print "Socket Item connecting to $host on port $port\n"
&::print_log ("[Socket_Item] Connecting to $host on port $port")
if $main::Debug{socket};
if (
my $sock = new IO::Socket::INET->new(
Expand All @@ -163,14 +162,11 @@ sub start {
return $sock;
}
else {
print
"Socket_Item client start error: could not start a tcp client socket\n"
. " - host=$host port=$port: $@\n";
&::print_log ("[Socket_Item] client start error: could not start a tcp client socket - host=$host port=$port: $@");
}
}
else {
print
"Socket_Item client start error: address is not in the form host:port. open failed. port=$port_name address=$host_port\n";
&::print_log ("[Socket_Item] client start error: address is not in the form host:port. Open failed. port=$port_name address $host_port");
}
return 0;
}
Expand Down Expand Up @@ -406,15 +402,13 @@ sub set {

my $port_name = $self->{port_name};

print
"Socket_Item: self=$self port=$port_name state=$state ip=$ip_address data=$socket_data\n"
&::print_log ("[Socket_Item] self=$self port=$port_name state=$state ip=$ip_address data=$socket_data")
if $main::Debug{socket};

return if $main::Save{mode} and $main::Save{mode} eq 'offline';

unless ( $main::Socket_Ports{$port_name}{sock} ) {
print
"Error, socket port $port_name has not been set: data=$socket_data\n";
&::print_log ("[Socket_Item] Error, socket port $port_name has not been set: data=$socket_data");
return;
}

Expand All @@ -430,16 +424,14 @@ sub set {
$main::Socket_Ports{$port_name}{clients}[$ip_address][0];
}
else {
print
"Socket_Item: Error, set client ip number $ip_address is not active\n";
&::print_log ("[Socket_Item] Error, set client ip number $ip_address is not active");
}
}
else {
for my $ptr ( @{ $main::Socket_Ports{$port_name}{clients} } ) {
my ( $socka, $client_ip_address, $client_port, $data ) =
@{$ptr};
print
"Testing socket client ip address: $client_ip_address:$client_port\n"
&::print_log ("[Socket_Item] Testing socket client ip address: $client_ip_address:$client_port")
if $main::Debug{socket};
push @sockets, $socka
if $socka and $client_ip_address =~ /$ip_address/
Expand All @@ -459,8 +451,7 @@ sub set {
}

unless (@sockets) {
print
"Error, socket port $port_name is not active on a socket_item set for data=$socket_data\n";
&::print_log ("[Socket_Item] Error, socket port $port_name is not active on a socket_item set for data=$socket_data");
return;
}

Expand All @@ -473,7 +464,7 @@ sub set {

for my $sock (@sockets) {
next unless $sock; # Shouldn't need this ?
print "db print to $sock: $socket_data\n" if $main::Debug{socket};
&::print_log ("[Socket_Item] db print to $sock: $socket_data") if $main::Debug{socket};
print $sock $socket_data;
}

Expand Down Expand Up @@ -503,22 +494,22 @@ Used to send a series of strings to the port, waiting for a specified prompt for
sub set_expect_check {
my ($self) = @_;
if ( my $data = said $self) {
print "set_expect: $$self{port_name} said $data\n";
&::print_log ("[Socket_Item] set_expect: $$self{port_name} said $data");
my $prompt = quotemeta ${ $$self{set_expect_cmds} }[0];
if ( $data =~ /$prompt/i ) {
my ( $prompt, $cmd ) = splice @{ $$self{set_expect_cmds} }, 0, 2;
&main::print_log("set_expect: $$self{port_name} $prompt");
&::print_log ("[Socket_Item] set_expect: $$self{port_name} $prompt");
$self->set( $cmd . "\n" );
unless ( @{ $$self{set_expect_cmds} } ) {
&main::print_log("set_expect: $$self{port_name} done");
&::print_log ("[Socket_Item] set_expect: $$self{port_name} done");
$self->stop;
$$self{set_expect_timer}->unset;
&::MainLoop_pre_drop_hook( \&Socket_Item::set_expect_check );
}
}
}
if ( $$self{set_expect_timer}->expired ) {
&main::print_log("set_expect: $$self{port_name} timed out");
&::print_log ("[Socket_Item] set_expect: $$self{port_name} timed out");
$self->stop;
&::MainLoop_pre_drop_hook( \&Socket_Item::set_expect_check );
}
Expand Down