logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Re: Patch to add APR::Socket->poll(): msg#00431

apache.mod-perl.devel

Subject: Re: Patch to add APR::Socket->poll()


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:stas@xxxxxxxxxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com


<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo