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:\>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|