akagrawal3 has asked for the wisdom of the Perl Monks concerning the following question:
is in execution, I believe that the getline() function reads the result which the device writes on its write end. Now my point of concern is for how long will the function getline() wait. I mean that the device may take time in processing the query and writing to the write end. Also what if the device never writes anything to its write end. I am not able to find exactly where this getline() function is defined or explained. Kindly help :)while (my $line = $socket->getline() ) { chomp $line; print {$file_handle} $line; }
foreach my $child (@hosts) { my $ident = $child->ident(); my $pid = fork; if ( !$pid ) { my $socket = IO::Socket::INET->new( PeerAddr => $child->get_ip(), PeerPort => $child->get_port(), Proto => 'tcp', Timeout => $child->get_timeout(), ); my @returned_lines; ## no critic(RequireBriefOpen) open my $file_handle, q{>}, CCI::data_path() . $reque +st->get_session_id() . q{/} . $child->get_ip() . '.log'; if ( !$socket ) { $request->error( sprintf 'Unable to connect to %s +: %s', $child->get_ip(), $! ); $returned_lines[0] = sprintf 'ERROR Unable to co +nnect to %s E RROR',$child->get_ip(); print {$file_handle} join q{}, @returned_lines or $request->error('Cannot print to per LGP f +ile'); CORE::exit 0; } $query = $parser->parse_string($query)->toString(1); $socket->print($query); while (my $line = $socket->getline() ) { chomp $line; print {$file_handle} $line; } close $file_handle; # use critic #print {$parent_handle} join q{}, @returned_lines # or $request->error('Cannot return values through + pipe'); CORE::exit 0; } else { push @children, $pid; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket::INET->getline() function
by zentara (Cardinal) on Apr 27, 2012 at 10:39 UTC | |
by akagrawal3 (Beadle) on Apr 27, 2012 at 11:30 UTC | |
by zentara (Cardinal) on Apr 27, 2012 at 14:37 UTC |