CC: | Hans Dieter Pearcey <hdp [...] weftsoar.net> |
Subject: | [PATCH] xdg reports select() is problematic on win32 |
Date: | Sat, 11 Apr 2009 18:33:54 -0400 |
To: | bug-HTTP-Server-Simple [...] rt.cpan.org |
From: | hdp [...] cpan.org |
From: Hans Dieter Pearcey <hdp@weftsoar.net>
---
lib/HTTP/Server/Simple.pm | 18 +++++++++++++++++-
1 files changed, 17 insertions(+), 1 deletions(-)
diff --git a/lib/HTTP/Server/Simple.pm b/lib/HTTP/Server/Simple.pm
index ad594c1..7ca560d 100755
--- a/lib/HTTP/Server/Simple.pm
+++ b/lib/HTTP/Server/Simple.pm
@@ -204,6 +204,22 @@ started process. Any arguments will be passed through to L</run>.
=cut
+my $HAS_TIME_HIRES;
+my $HAS_OK_SELECT;
+BEGIN { $HAS_TIME_HIRES = eval { require Time::HiRes; 1 } }
+BEGIN { $HAS_OK_SELECT = $^O ne "MSWin32" }
+
+sub _background_sleep {
+ if ($HAS_TIME_HIRES) {
+ Time::HiRes::usleep(100_000);
+ } elsif ($HAS_OK_SELECT) {
+ select(undef, undef, undef, 0.1);
+ } else {
+ sleep 1;
+ }
+}
+
+
sub background {
my $self = shift;
require File::Temp;
@@ -213,7 +229,7 @@ sub background {
croak "Can't fork: $!" unless defined($child);
if ($child) {
while (eof($fh)) {
- select(undef, undef, undef, 0.1);
+ _background_sleep();
seek($fh, 0, 0);
}
return $child;
--
1.6.1.2