From a48570a046d593e3f603e031e294527a9cf31cdb Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Wed, 23 Oct 2013 15:50:10 +0200 Subject: [PATCH] windows: Provide a cancellable usleep(), but with ms resolution only --- src/libstrongswan/utils/windows.c | 13 +++++++++++++ src/libstrongswan/utils/windows.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/src/libstrongswan/utils/windows.c b/src/libstrongswan/utils/windows.c index a0ff6b84b..4a6a35eff 100644 --- a/src/libstrongswan/utils/windows.c +++ b/src/libstrongswan/utils/windows.c @@ -36,6 +36,19 @@ void windows_deinit() WSACleanup(); } +/** + * See header + */ +int usleep(useconds_t usec) +{ + if (usec > 0 && usec < 1000) + { /* do not Sleep(0) for small values */ + usec = 1000; + } + SleepEx(usec / 1000, TRUE); + return 0; +} + /** * See header */ diff --git a/src/libstrongswan/utils/windows.h b/src/libstrongswan/utils/windows.h index afa524242..8e6fd80b1 100644 --- a/src/libstrongswan/utils/windows.h +++ b/src/libstrongswan/utils/windows.h @@ -85,6 +85,11 @@ static inline int sleep(unsigned int seconds) return 0; } +/** + * Replacement of usleep(3), cancellable, ms resolution only + */ +int usleep(useconds_t usec); + /** * strdup(3), the Windows variant can't free(strdup("")) and others */