From 16e1a2716e4ab0e36b68198256c35675a019ebf0 Mon Sep 17 00:00:00 2001 From: Neil Kolban Date: Sun, 12 Mar 2017 22:32:00 -0500 Subject: [PATCH] mbedtls port: Fix detection of EWOULDBLOCK/EAGAIN with non-blocking sockets Previous code read non-blocking status via fcntl first, which resets errno. Closes #424 https://github.com/espressif/esp-idf/pull/424 Merges #425 https://github.com/espressif/esp-idf/pull/425 --- components/mbedtls/port/net.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/mbedtls/port/net.c b/components/mbedtls/port/net.c index bb0884ac87..459106b405 100644 --- a/components/mbedtls/port/net.c +++ b/components/mbedtls/port/net.c @@ -203,6 +203,8 @@ int mbedtls_net_bind( mbedtls_net_context *ctx, const char *bind_ip, const char */ static int net_would_block( const mbedtls_net_context *ctx ) { + int error = mbedtls_net_errno(ctx->fd); + /* * Never return 'WOULD BLOCK' on a non-blocking socket */ @@ -210,8 +212,6 @@ static int net_would_block( const mbedtls_net_context *ctx ) return ( 0 ); } - int error = mbedtls_net_errno(ctx->fd); - switch ( error ) { #if defined EAGAIN case EAGAIN: