Use SOMAXCONN in C::E::H::Daemon
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Engine / HTTP / Daemon.pm
index 8360d9d..52a559a 100644 (file)
@@ -4,6 +4,29 @@ use strict;
 use base 'Catalyst::Engine::HTTP::Base';
 
 use IO::Select;
+use IO::Socket;
+
+BEGIN {
+
+    if ( $^O eq 'MSWin32' ) {
+
+       *EINPROGRESS = sub { 10036 };
+       *EWOULDBLOCK = sub { 10035 };
+       *F_GETFL     = sub {     0 };
+       *F_SETFL     = sub {     0 };
+
+       *IO::Socket::blocking = sub {
+           my ( $self, $blocking ) = @_;
+           my $nonblocking = $blocking ? 0 : 1;
+           ioctl( $self, 0x8004667e, \$nonblocking );
+       };
+    }
+
+    else {
+        Errno->require;
+        Errno->import( qw[EWOULDBLOCK EINPROGRESS] );
+    }
+}
 
 =head1 NAME
 
@@ -64,7 +87,7 @@ sub run {
     $SIG{'PIPE'} = 'IGNORE';
 
     my $daemon = Catalyst::Engine::HTTP::Daemon::Catalyst->new(
-        Listen    => 1,
+        Listen    => SOMAXCONN,
         LocalPort => $port,
         ReuseAddr => 1,
         Timeout   => 5
@@ -82,7 +105,7 @@ sub run {
 
     while (1) {
 
-        for my $client ( $select->can_read(0.01) ) {
+        for my $client ( $select->can_read(1) ) {
 
             if ( $client == $daemon ) {
                 $client = $daemon->accept;
@@ -135,7 +158,7 @@ sub run {
             $class->handler( $client->request, $client->response, $client );
         }
 
-        for my $client ( $select->can_write(0.01) ) {
+        for my $client ( $select->can_write(1) ) {
 
             next unless $client->response;