From 9aaca09044de4d4116822f25d2cf9c780d7465ce Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Wed, 4 Mar 2020 11:44:49 +0100 Subject: tests: try to make sleeping portable by avoiding select select does not support just waiting on Windows: https://perldoc.perl.org/perlport.html#select Reviewed-By: Daniel Stenberg Closes #5035 --- tests/ftp.pm | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'tests/ftp.pm') diff --git a/tests/ftp.pm b/tests/ftp.pm index f4a4acedd..f7298bce6 100644 --- a/tests/ftp.pm +++ b/tests/ftp.pm @@ -5,7 +5,7 @@ # | (__| |_| | _ <| |___ # \___|\___/|_| \_\_____| # -# Copyright (C) 1998 - 2010, Daniel Stenberg, , et al. +# Copyright (C) 1998 - 2020, Daniel Stenberg, , et al. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. The terms @@ -20,6 +20,14 @@ # ########################################################################### +BEGIN { + # portable sleeping needs Time::HiRes + eval { + no warnings "all"; + require Time::HiRes; + } +} + use strict; use warnings; @@ -29,6 +37,27 @@ use serverhelp qw( datasockf_pidfilename ); +####################################################################### +# portable_sleep uses Time::HiRes::sleep if available and falls back +# to the classic approach of using select(undef, undef, undef, ...). +# even though that one is not portable due to being implemented using +# select on Windows: https://perldoc.perl.org/perlport.html#select +# On Windows it also just uses full-second sleep for waits >1 second. +# +sub portable_sleep { + my ($seconds) = @_; + + if($Time::HiRes::VERSION) { + Time::HiRes::sleep($seconds); + } + elsif ($seconds > 1 && ($^O eq 'MSWin32' || $^O eq 'msys')) { + sleep($seconds); + } + else { + select(undef, undef, undef, $seconds); + } +} + ####################################################################### # pidfromfile returns the pid stored in the given pidfile. The value # of the returned pid will never be a negative value. It will be zero @@ -216,7 +245,7 @@ sub killpid { } } last if(not scalar(@signalled)); - select(undef, undef, undef, 0.05); + portable_sleep(0.05); } } -- cgit v1.2.3 From a6fed41f6f12f3b71cfe85609f02a294b972d3d3 Mon Sep 17 00:00:00 2001 From: Marc Hoersken Date: Sat, 7 Mar 2020 11:01:57 +0100 Subject: tests: use native Sleep function as fallback on Windows Reviewed-By: Daniel Stenberg Closes #5054 --- tests/ftp.pm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'tests/ftp.pm') diff --git a/tests/ftp.pm b/tests/ftp.pm index f7298bce6..5e92ce7f9 100644 --- a/tests/ftp.pm +++ b/tests/ftp.pm @@ -25,6 +25,11 @@ BEGIN { eval { no warnings "all"; require Time::HiRes; + }; + # portable sleeping falls back to native Sleep on Win32 + eval { + no warnings "all"; + require Win32; } } @@ -50,8 +55,8 @@ sub portable_sleep { if($Time::HiRes::VERSION) { Time::HiRes::sleep($seconds); } - elsif ($seconds > 1 && ($^O eq 'MSWin32' || $^O eq 'msys')) { - sleep($seconds); + elsif ($^O eq 'MSWin32' || $^O eq 'cygwin' || $^O eq 'msys') { + Win32::Sleep($seconds*1000); } else { select(undef, undef, undef, $seconds); -- cgit v1.2.3