Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Strange blocking issue with HTTP::Daemon

by Khen1950fx (Canon)
on Aug 10, 2010 at 22:58 UTC ( #854163=note: print w/ replies, xml ) Need Help??


in reply to Strange blocking issue with HTTP::Daemon

Net::Server::NonBlocking might help. It can handle up to 512 clients, at least on Linux. Take a look at the server template.


Comment on Re: Strange blocking issue with HTTP::Daemon
Re^2: Strange blocking issue with HTTP::Daemon
by isync (Hermit) on Aug 10, 2010 at 23:28 UTC
    Can someone explain to me what is happening here? Come on, monks..
    Why is a vanilla HTTP::Daemon behaving like that, and what must be done to solve it?

    A bit unsatisfactory to switch to Net::Server. Especially as the ::HTTP personality is so far less usable than HTTP::Daemon's...

    And: Doesn't the ancient Net::Server::NonBlocking effectively do the same as the ::Fork'ing ::PreForkin'ing etc. personas? As said, I've tried a script around Net::Server::etc. and it showed the same behaviour (if I remember correctly). I might port my test-server.pl to Net::Server::MultiType, but I would prefer understanding why I invest this effort.

      Replying to an ancient post but this is little to do with HTTP::Daemon. The issue is that once you have accepted a connection you loop processing its requests until it goes away. With the LWP::UserAgent it appears to close the connection after each request but a web browser will attempt to keep the connection open meaning your code will block on the get_request.

      The example code in the HTTP:Daemon synopsis is the problem. The code below is how I use HTTP::Daemon. Instead of blocking in the get_request call I put the daemon and client connections in an IO::Select object and block on that and only process data from those that are ready. That way a single threaded server can appear to be processing data concurrently from multiple connections including regular browsers that will keep the connection open.

      my $d = HTTP::Daemon->new( LocalAddr => 'localhost', LocalPort => 4242, ReuseAddr => 1) || die; my $select = IO::Select->new(); $select->add($d); while ($select->count()) { my @ready = $select->can_read(); # Blocking foreach my $connection (@ready) { if ($connection == $d) { # on the daemon so accept and add the connection my $client = $connection->accept(); $select->add($client); } else { # is a client connection my $request = $connection->get_request(); if ($request) { # process the request } else { # connection closed by the client $select->remove($connection); $connection->close(); # probably not necessary } } # end processing connections with data }

      Now back to investigating the problem I was originally looking at. Why does get_request block on malformed / incomplete requests.......

        HTTP::Daemon::ClientConn::get_request blocks until it has a correct request because that's what it is documented to do.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://854163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-08-28 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (261 votes), past polls