Unfortunately I am not wrong. The hanging behaviour is real. The underlying reason is LWP::Simple uses (for http) the _http_trivial_get() function, not LWP::UserAgent. This implements a 60 second IO::Socket::INET make connection timeout, but no timeout on data recieve. Modifying the test code to use LWP::Simple proves the point (LWP::Simple will wait 500 seconds to get the data - it gets an instant socket, then nothing for 500 seconds). This function remains active in the latest LWP::Simple.
I agree it should really be a subclass of LWP::UserAgent but for http it is not. The timeout behaviour for LWP::Simple and LWP::UserAgent could IMHO use some work.
C:\>type server.pl
#!/usr/bin/perl
use IO::Socket;
use IO::Select;
$lsn = IO::Socket::INET->new( Listen => 1,
LocalAddr => 'localhost',
LocalPort => 9000,);
my $client = new IO::Select( $lsn );
while( my @ready = $client->can_read ) {
for my $fh (@ready) {
if($fh == $lsn) {
warn "Accepted new socket\n";
my $new = $lsn->accept;
$client->add($new);
}
else {
# Process socket
warn "Getting data\n";
$data = <$fh>; # yeah yeah
warn "Got $data\nDoing nothing forever!\n";
my @response = split '', "HTTP/1.1 200 OK\n\nHello World!\
+n";
sleep 500;
print {$fh} @response;
$client->remove($fh);
$fh->close();
}
}
}
C:\>type lwp.pl
#!/usr/bin/perl
$|++;
use LWP::Simple;
$start = time();
print "Begin at $start\n";
$response = get('http://localhost:9000/');
$end = time();
my $time = $end - $start;
print "Done at $end\nTook $time seconds\nGot:\n$response\n";
C:\>perl lwp.pl
Begin at 1087868116
Done at 1087868616
Took 500 seconds
Got:
Hello World!
C:\>
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|