Greetings Monks, I would like to seek your help in a doubt I have. In the below code, @hosts stores the details of devices like RTR, HUB etc which it tries to connect to. When I say devices I mean 'n' number of devices. I try to connect to all of these devices by forking and writing a query which is in XML through $socket->print($query); when
while (my $line = $socket->getline() ) { chomp $line; print {$file_handle} $line; }
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 :)
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; } }

In reply to IO::Socket::INET->getline() function by akagrawal3

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.