gert
gert

Reputation: 75

How do I get Perl's HTTP::Daemon to accept more than one connection?

I do some testing with HTTP::Daemon:

use HTTP::Daemon;
use HTTP::Status;

my $d = HTTP::Daemon->new || die;
print "Please contact me at: <URL:", $d->url, ">\n";
while (my $c = $d->accept) {
  while (my $r = $c->get_request) {
      if ($r->method eq 'GET') {
          # do some action (about 10s)
      }
      else {
          $c->send_error(RC_FORBIDDEN)
      }
    }
  $c->close;
  undef($c);
}

It works fine, but if I do more request within 10s, the requests gets queued (I get all requests through $d->accept)

What I want is the following: if a client starts a request, no other should be queued.
I tried with the Listen option, but without success.

Any suggestions?

Upvotes: 0

Views: 857

Answers (2)

chris
chris

Reputation: 21

you have one thread here; it can either handle the first request or handle the next one to come in. You can't deal with new requests until control goes back to accept.

Upvotes: 2

JB.
JB.

Reputation: 42094

HTTP::Daemon doesn't fork for you, and explicitely tells you so in its documentation.

This HTTP daemon does not fork(2) for you. Your application, i.e. the user of the "HTTP::Daemon" is responsible for forking if that is desirable. Also note that the user is responsible for generating responses that conform to the HTTP/1.1 protocol.

If your answering takes too long, fork to answer. Or use another module.

Upvotes: 4

Related Questions