diff --git a/include/polarssl/net.h b/include/polarssl/net.h index 5f389f8258..f5b3f4252a 100644 --- a/include/polarssl/net.h +++ b/include/polarssl/net.h @@ -35,6 +35,15 @@ #include +#if defined(POLARSSL_HAVE_TIME) +#if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32) +#include +typedef UINT32 uint32_t; +#else +#include +#endif +#endif /* POLARSSL_HAVE_TIME */ + #define POLARSSL_ERR_NET_SOCKET_FAILED -0x0042 /**< Failed to open a socket. */ #define POLARSSL_ERR_NET_CONNECT_FAILED -0x0044 /**< The connection to the given server / port failed. */ #define POLARSSL_ERR_NET_BIND_FAILED -0x0046 /**< Binding of the socket failed. */ @@ -178,7 +187,7 @@ int net_send( void *ctx, const unsigned char *buf, size_t len ); * \param ctx Socket * \param buf The buffer to write to * \param len Maximum length of the buffer - * \param timeout Maximum number of seconds to wait for data + * \param timeout Maximum number of milliseconds to wait for data * * \return This function returns the number of bytes received, * or a non-zero error code: @@ -191,7 +200,7 @@ int net_send( void *ctx, const unsigned char *buf, size_t len ); * requires a different strategy. */ int net_recv_timeout( void *ctx, unsigned char *buf, size_t len, - unsigned char timeout ); + uint32_t timeout ); #endif /* POLARSSL_HAVE_TIME */ /** diff --git a/include/polarssl/ssl.h b/include/polarssl/ssl.h index 9ff1d4f544..f3f357522e 100644 --- a/include/polarssl/ssl.h +++ b/include/polarssl/ssl.h @@ -778,7 +778,7 @@ struct _ssl_context void (*f_dbg)(void *, int, const char *); int (*f_send)(void *, const unsigned char *, size_t); int (*f_recv)(void *, unsigned char *, size_t); - int (*f_recv_timeout)(void *, unsigned char *, size_t, unsigned char); + int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t); int (*f_get_cache)(void *, ssl_session *); int (*f_set_cache)(void *, const ssl_session *); @@ -1194,8 +1194,8 @@ void ssl_set_bio_timeout( ssl_context *ssl, void *p_bio, int (*f_send)(void *, const unsigned char *, size_t), int (*f_recv)(void *, unsigned char *, size_t), - int (*f_recv_timeout)(void *, unsigned char *, size_t, unsigned char), - unsigned char timeout ); + int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t), + uint32_t timeout ); #if defined(POLARSSL_SSL_DTLS_HELLO_VERIFY) /** diff --git a/library/net.c b/library/net.c index 7336f212df..9d0266119f 100644 --- a/library/net.c +++ b/library/net.c @@ -585,10 +585,10 @@ int net_recv( void *ctx, unsigned char *buf, size_t len ) #if defined(POLARSSL_HAVE_TIME) /* - * Read at most 'len' characters, blocking for at most 'timeout' seconds + * Read at most 'len' characters, blocking for at most 'timeout' ms */ int net_recv_timeout( void *ctx, unsigned char *buf, size_t len, - unsigned char timeout ) + uint32_t timeout ) { int ret; struct timeval tv; @@ -598,8 +598,8 @@ int net_recv_timeout( void *ctx, unsigned char *buf, size_t len, FD_ZERO( &read_fds ); FD_SET( fd, &read_fds ); - tv.tv_sec = timeout; - tv.tv_usec = 0; + tv.tv_sec = timeout / 1000; + tv.tv_usec = ( timeout % 1000 ) * 1000; ret = select( fd + 1, &read_fds, NULL, NULL, &tv ); diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 215f005546..34ef165c9b 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -1990,7 +1990,7 @@ int ssl_fetch_input( ssl_context *ssl, size_t nb_want ) ssl->handshake != NULL ) /* No timeout outside handshake */ { ret = ssl->f_recv_timeout( ssl->p_bio, ssl->in_hdr, len, - ssl->handshake->retransmit_timeout / 1000 ); + ssl->handshake->retransmit_timeout ); } else ret = ssl->f_recv( ssl->p_bio, ssl->in_hdr, len ); @@ -4936,8 +4936,8 @@ void ssl_set_bio_timeout( ssl_context *ssl, void *p_bio, int (*f_send)(void *, const unsigned char *, size_t), int (*f_recv)(void *, unsigned char *, size_t), - int (*f_recv_timeout)(void *, unsigned char *, size_t, unsigned char), - unsigned char timeout ) + int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t), + uint32_t timeout ) { ssl->p_bio = p_bio; ssl->f_send = f_send;