You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@perl.apache.org by "Philippe M. Chiasson" <go...@ectoplasm.org> on 2004/07/26 06:57:53 UTC

[Patch mp2] recv() and EAGAIN in protocol/pseudo_http on OSX

Just stumbled on a little bug with protocol/pseudo_http on OSX.

The readline function that calls APR::Socket::recv() seems to assume
non-blocking IO, and it caused the problem, with EAGAIN being
return right away.

The following little patch fixes the problem by making sure the
socket is in blocking.

With the patch, the test passes OK 100% of the time.

Index: t/protocol/TestProtocol/pseudo_http.pmestProtocol/pseudo_http.pm 
| patch -
===================================================================
RCS file: /home/cvs/modperl-2.0/t/protocol/TestProtocol/pseudo_http.pm,v
retrieving revision 1.3
diff -u -I$Id -r1.3 pseudo_http.pm
--- t/protocol/TestProtocol/pseudo_http.pm      6 Jul 2004 18:51:55 
-0000       1.3
+++ t/protocol/TestProtocol/pseudo_http.pm      26 Jul 2004 04:57:25 -0000
@@ -18,6 +18,7 @@
 use APR::Socket ();
 
 use Apache::Const -compile => qw(OK DONE DECLINED);
+use APR::Const -compile => qw(SO_NONBLOCK);
 
 my @cmds = qw(date quit);
 my %commands = map { $_, \&{$_} } @cmds;
@@ -25,6 +26,10 @@
 sub handler {
     my $c = shift;
     my $socket = $c->client_socket;
+   
+    if ($socket->opt_get(APR::SO_NONBLOCK)) {
+        $socket->opt_set(APR::SO_NONBLOCK => 0);
+    }
 
     if ((my $rc = greet($c)) != Apache::OK) {
         $socket->send("Say HELO first\n");

Re: [Patch mp2] recv() and EAGAIN in protocol/pseudo_http on OSX

Posted by Stas Bekman <st...@stason.org>.
Philippe M. Chiasson wrote:
> Just stumbled on a little bug with protocol/pseudo_http on OSX.
> 
> The readline function that calls APR::Socket::recv() seems to assume
> non-blocking IO, and it caused the problem, with EAGAIN being
> return right away.
> 
> The following little patch fixes the problem by making sure the
> socket is in blocking.
> 
> With the patch, the test passes OK 100% of the time.

Yeah, the same old problem. +1

We really ought to figure out why Apache doesn't do the right thing and 
handle that on the mod_perl level if Apache doesn't. It sucks to 
remember to fix that thing all the time in the tests.

> Index: t/protocol/TestProtocol/pseudo_http.pmestProtocol/pseudo_http.pm 
> | patch -
> ===================================================================
> RCS file: /home/cvs/modperl-2.0/t/protocol/TestProtocol/pseudo_http.pm,v
> retrieving revision 1.3
> diff -u -I$Id -r1.3 pseudo_http.pm
> --- t/protocol/TestProtocol/pseudo_http.pm      6 Jul 2004 18:51:55 
> -0000       1.3
> +++ t/protocol/TestProtocol/pseudo_http.pm      26 Jul 2004 04:57:25 -0000
> @@ -18,6 +18,7 @@
> use APR::Socket ();
> 
> use Apache::Const -compile => qw(OK DONE DECLINED);
> +use APR::Const -compile => qw(SO_NONBLOCK);
> 
> my @cmds = qw(date quit);
> my %commands = map { $_, \&{$_} } @cmds;
> @@ -25,6 +26,10 @@
> sub handler {
>     my $c = shift;
>     my $socket = $c->client_socket;
> +   +    if ($socket->opt_get(APR::SO_NONBLOCK)) {
> +        $socket->opt_set(APR::SO_NONBLOCK => 0);
> +    }
> 
>     if ((my $rc = greet($c)) != Apache::OK) {
>         $socket->send("Say HELO first\n");


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org