From: Vincent Pit Date: Mon, 20 Apr 2015 14:19:11 +0000 (-0300) Subject: Add a select()-based usleep() implementation X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=6e034dba301409cee65c0f76f094eb8eb4b42110;p=perl%2Fmodules%2FVPIT-TestHelpers.git Add a select()-based usleep() implementation --- diff --git a/lib/VPIT/TestHelpers.pm b/lib/VPIT/TestHelpers.pm index 65fc256..f45da91 100644 --- a/lib/VPIT/TestHelpers.pm +++ b/lib/VPIT/TestHelpers.pm @@ -718,6 +718,25 @@ sub init_usleep { return undef; } }, + 'select' => sub { + if ($Config::Config{d_select}) { + diag 'Using select()-based fallback usleep()'; + return sub { + my $s = $_[0]; + my $r = 0; + while ($s > 0) { + my ($found, $t) = select(undef, undef, undef, $s / 1e6); + last unless defined $t; + $t = int($t * 1e6); + $s -= $t; + $r += $t; + } + return $r; + }; + } else { + return undef; + } + }, 'sleep' => sub { diag 'Using sleep()-based fallback usleep()'; return sub { @@ -728,7 +747,7 @@ sub init_usleep { }, ); - @impls = qw unless @impls; + @impls = qw unless @impls; my $usleep; for my $impl (@impls) { diff --git a/t/50-usleep.t b/t/50-usleep.t index c1fc98f..15592ec 100644 --- a/t/50-usleep.t +++ b/t/50-usleep.t @@ -7,7 +7,7 @@ use VPIT::TestHelpers; use Test::More; -my @impls = qw; +my @impls = qw; for my $impl (@impls) { my $desc = "$impl-based usleep()";