Add guards for closed socket in net.c
This is particularly problematic when calling FD_SET( -1, ... ), but let's
check it in all functions.
This was introduced with the new API and the fact the net_free() now sets the
internal fd to -1 in order to mark it as closed: now using this information.
diff --git a/library/error.c b/library/error.c
index 21be423..e78057b 100644
--- a/library/error.c
+++ b/library/error.c
@@ -640,6 +640,8 @@
mbedtls_snprintf( buf, buflen, "NET - Failed to get an IP address for the given hostname" );
if( use_ret == -(MBEDTLS_ERR_NET_BUFFER_TOO_SMALL) )
mbedtls_snprintf( buf, buflen, "NET - Buffer is too small to hold the data" );
+ if( use_ret == -(MBEDTLS_ERR_NET_INVALID_CONTEXT) )
+ mbedtls_snprintf( buf, buflen, "NET - The context is invalid, eg because it was free()ed" );
#endif /* MBEDTLS_NET_C */
#if defined(MBEDTLS_OID_C)