开发者

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

开发者 https://www.devze.com 2023-02-11 01:09 出处:网络
I do some testing with HTTP::Daemon: use HTTP::Daemon; use HTTP::Status; my $d = HTTP::Daemon->new || die;

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消