From a91d85e331098429a9c159c8dcaedbefbe0504ea Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Fri, 15 Jan 2016 14:36:08 +0000 Subject: [PATCH] Fix for net_usleep() timing selftest on mingw In mingw32, net_usleep() was failing to sleep for the given period, and was sleeping in microseconds, not milliseconds. Fix backported from mbed TLS 2.x of using the Win32 Sleep() API call rather than using the timeout of select(). --- library/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/net.c b/library/net.c index dcbe480e2..c7ce2584e 100644 --- a/library/net.c +++ b/library/net.c @@ -500,15 +500,19 @@ int net_set_nonblock( int fd ) */ void net_usleep( unsigned long usec ) { +#if defined(_WIN32) + Sleep( ( usec + 999 ) / 1000 ); +#else struct timeval tv; tv.tv_sec = usec / 1000000; -#if !defined(_WIN32) && ( defined(__unix__) || defined(__unix) || \ - ( defined(__APPLE__) && defined(__MACH__) ) ) +#if defined(__unix__) || defined(__unix) || \ + ( defined(__APPLE__) && defined(__MACH__) ) tv.tv_usec = (suseconds_t) usec % 1000000; #else tv.tv_usec = usec % 1000000; #endif select( 0, NULL, NULL, NULL, &tv ); +#endif } #endif /* POLARSSL_HAVE_TIME */