net_is_block() renamed to net_would_block() and corrected behaviour on
non-blocking sockets

net_would_block() now does not return 1 if the socket is blocking.
diff --git a/library/net.c b/library/net.c
index 46902df..24dd95e 100644
--- a/library/net.c
+++ b/library/net.c
@@ -357,15 +357,31 @@
 #endif /* POLARSSL_HAVE_IPV6 */
 }
 
-/*
- * Check if the current operation is blocking
- */
-static int net_is_blocking( void )
-{
 #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
     !defined(EFI32)
+/*
+ * Check if the requested operation would be blocking on a non-blocking socket
+ * and thus 'failed' with a negative return value.
+ */
+static int net_would_block( int fd )
+{
     return( WSAGetLastError() == WSAEWOULDBLOCK );
+}
 #else
+/*
+ * Check if the requested operation would be blocking on a non-blocking socket
+ * and thus 'failed' with a negative return value.
+ *
+ * Note: on a blocking socket this function always returns 0!
+ */
+static int net_would_block( int fd )
+{
+    /*
+     * Never return 'WOULD BLOCK' on a non-blocking socket
+     */
+    if( ( fcntl( fd, F_GETFL ) & O_NONBLOCK ) != O_NONBLOCK )
+        return( 0 );
+
     switch( errno )
     {
 #if defined EAGAIN
@@ -377,8 +393,8 @@
             return( 1 );
     }
     return( 0 );
-#endif
 }
+#endif
 
 /*
  * Accept a connection from a remote client
@@ -403,7 +419,7 @@
 
     if( *client_fd < 0 )
     {
-        if( net_is_blocking() != 0 )
+        if( net_would_block( *client_fd ) != 0 )
             return( POLARSSL_ERR_NET_WANT_READ );
 
         return( POLARSSL_ERR_NET_ACCEPT_FAILED );
@@ -476,11 +492,12 @@
  */
 int net_recv( void *ctx, unsigned char *buf, size_t len )
 {
-    int ret = read( *((int *) ctx), buf, len );
+    int fd = *((int *) ctx);
+    int ret = read( fd, buf, len );
 
     if( ret < 0 )
     {
-        if( net_is_blocking() != 0 )
+        if( net_would_block( fd ) != 0 )
             return( POLARSSL_ERR_NET_WANT_READ );
 
 #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
@@ -506,11 +523,12 @@
  */
 int net_send( void *ctx, const unsigned char *buf, size_t len )
 {
-    int ret = write( *((int *) ctx), buf, len );
+    int fd = *((int *) ctx);
+    int ret = write( fd, buf, len );
 
     if( ret < 0 )
     {
-        if( net_is_blocking() != 0 )
+        if( net_would_block( fd ) != 0 )
             return( POLARSSL_ERR_NET_WANT_WRITE );
 
 #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \