Another thing is the test. First of all it's quite possible that on a slow machine the first subtest will fail, so it should probably wait much longer on the first call.


Second, I'd like to see is replacing sleep 2 with something faster. The test suite is already huge and adding extra sleeps adds up to a long run time. I think the test can be rewritten as so:


--- /dev/null 1969-12-31 19:00:00.000000000 -0500
+++ t/protocol/echo_nonblock.t 2004-08-30 23:57:44.606577082 -0400
@@ -0,0 +1,27 @@
+use strict;
+use warnings FATAL => 'all';
+
+use Test;
+use Apache::TestUtil;
+use Apache::TestRequest ();
+
+plan tests => 3;
+
+my $socket = Apache::TestRequest::vhost_socket('TestProtocol::echo_nonblock');
+
+ok $socket;
+
+my $received;
+my $expected;
+
+$expected = "nonblocking";
+print $socket "$expected\n";
+chomp($received = <$socket> || '');
+ok t_cmp $received, $expected, "no timeout";
+
+# now get a timed out request
+$expected = "TIMEUP";
+print $socket "should timeout\n";
+chomp($received = <$socket> || '');
+ok t_cmp $received, $expected, "timed out";
+


--- /dev/null 1969-12-31 19:00:00.000000000 -0500
+++ t/protocol/TestProtocol/echo_nonblock.pm 2004-08-30 23:59:25.512107442 -0400
@@ -0,0 +1,59 @@
+package TestProtocol::echo_nonblock;
+
+# this test reads from/writes to the socket doing nonblocking IO
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Connection ();
+use APR::Socket ();
+
+use Apache::TestTrace;
+
+use Apache::Const -compile => 'OK';
+use APR::Const -compile => qw(SO_NONBLOCK TIMEUP SUCCESS POLLIN);
+
+use constant BUFF_LEN => 1024;
+
+sub handler {
+ my $c = shift;
+ my $socket = $c->client_socket;
+
+ $socket->opt_set(APR::SO_NONBLOCK => 1);
+
+ my $counter = 0;
+ my $timeout = 0;
+ while (1) {
+ if ($counter != 1) {
+ # Wait up to ten seconds for data to arrive.
+ $timeout = 10_000_000;
+ $counter++;
+ } elsif ($counter == 1) {
+ # this will certainly fail
+ $timeout = 0;
+ $counter++;
+ }
+
+ my $rc = $socket->poll($c->pool, $timeout, APR::POLLIN);
+ if ($rc == APR::SUCCESS) {
+ if ($socket->recv(my $buf, BUFF_LEN)) {
+ debug "no timeout";
+ $socket->send($buf);
+ }
+ else {
+ last;
+ }
+ }
+ elsif ($rc == APR::TIMEUP) {
+ debug "timeout";
+ $socket->send("TIMEUP\n");
+ }
+ else {
+ die "poll error: $rc: " . APR::Error::strerror($rc);
+ }
+ }
+
+ Apache::OK;
+}
+
+1;


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

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to