diff options
author | Marc Hoersken <info@marc-hoersken.de> | 2020-03-04 11:44:49 +0100 |
---|---|---|
committer | Marc Hoersken <info@marc-hoersken.de> | 2020-03-04 15:31:42 +0100 |
commit | 9aaca09044de4d4116822f25d2cf9c780d7465ce (patch) | |
tree | 143fcfc746a42c8b045f14f61ffc73a676e143fc /tests/ftp.pm | |
parent | 1eecb0e022423b92c79e8d946c78dcfc20ab56af (diff) | |
download | curl-9aaca09044de4d4116822f25d2cf9c780d7465ce.tar.gz |
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
Diffstat (limited to 'tests/ftp.pm')
-rw-r--r-- | tests/ftp.pm | 33 |
1 files changed, 31 insertions, 2 deletions
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, <daniel@haxx.se>, et al. +# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, 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; @@ -30,6 +38,27 @@ use serverhelp qw( ); ####################################################################### +# 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 # on any file related error or if a pid can not be extracted from the @@ -216,7 +245,7 @@ sub killpid { } } last if(not scalar(@signalled)); - select(undef, undef, undef, 0.05); + portable_sleep(0.05); } } |