From: Nikos Mavrogiannopoulos Date: Sun, 2 Mar 2014 09:37:05 +0000 (+0100) Subject: replace select() on windows X-Git-Tag: gnutls_3_3_0pre0~98 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=078e3914e824bc143324a57d508990ebecdadea5;p=thirdparty%2Fgnutls.git replace select() on windows --- diff --git a/src/common.h b/src/common.h index 927c175987..37912ecc43 100644 --- a/src/common.h +++ b/src/common.h @@ -34,6 +34,7 @@ #ifdef _WIN32 #include #include +#include #undef OCSP_RESPONSE #endif @@ -68,18 +69,23 @@ pin_callback(void *user, int attempt, const char *token_url, void pkcs11_common(void); #ifdef _WIN32 -# include -static int neterrno(void) +static int system_recv_timeout(gnutls_transport_ptr_t ptr, unsigned int ms) { -int err = WSAGetLastError(); - - if (err == WSAEWOULDBLOCK) - return EAGAIN; - else if (err == WSAEINTR) - return EINTR; - else if (err == WSAEINPROGRESS) - return EINPROGRESS; - return 0; + fd_set rfds; + struct timeval tv; + int ret, fd = (long)ptr; + + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + + tv.tv_sec = 0; + tv.tv_usec = ms * 1000; + while (tv.tv_usec >= 1000000) { + tv.tv_usec -= 1000000; + tv.tv_sec++; + } + + return select(fd + 1, &rfds, NULL, NULL, &tv); } static ssize_t @@ -99,8 +105,7 @@ void set_read_funcs(gnutls_session_t session) { gnutls_transport_set_push_function(session, system_write); gnutls_transport_set_pull_function(session, system_read); - gnutls_transport_set_errno_function(session, neterrno); - + gnutls_transport_set_pull_timeout_function(session, system_recv_timeout); } #else # define set_read_funcs(x)