return ( 0 );
}
-static int mbedtls_net_errno(int fd)
-{
- int sock_errno = 0;
- u32_t optlen = sizeof(sock_errno);
-
- getsockopt(fd, SOL_SOCKET, SO_ERROR, &sock_errno, &optlen);
-
- return sock_errno;
-}
-
/*
* Initialize a context
*/
*
* Note: on a blocking socket this function always returns 0!
*/
-static int net_would_block( const mbedtls_net_context *ctx, int *errout )
+static int net_would_block( const mbedtls_net_context *ctx )
{
- int error = mbedtls_net_errno(ctx->fd);
-
- if ( errout ) {
- *errout = error;
- }
+ int error = errno;
/*
* Never return 'WOULD BLOCK' on a non-blocking socket
*/
if ( ( fcntl( ctx->fd, F_GETFL, 0) & O_NONBLOCK ) != O_NONBLOCK ) {
+ errno = error;
return ( 0 );
}
- switch ( error ) {
+ switch ( errno = error ) {
#if defined EAGAIN
case EAGAIN:
#endif
}
if ( ret < 0 ) {
- if ( net_would_block( bind_ctx, NULL ) != 0 ) {
+ if ( net_would_block( bind_ctx ) != 0 ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
{
int ret;
int fd = ((mbedtls_net_context *) ctx)->fd;
- int error = 0;
if ( fd < 0 ) {
return ( MBEDTLS_ERR_NET_INVALID_CONTEXT );
ret = (int) read( fd, buf, len );
if ( ret < 0 ) {
- if ( net_would_block( ctx, &error ) != 0 ) {
+ if ( net_would_block( ctx ) != 0 ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
- if ( error == EPIPE || error == ECONNRESET ) {
+ if ( errno == EPIPE || errno == ECONNRESET ) {
return ( MBEDTLS_ERR_NET_CONN_RESET );
}
- if ( error == EINTR ) {
+ if ( errno == EINTR ) {
return ( MBEDTLS_ERR_SSL_WANT_READ );
}
int ret;
int fd = ((mbedtls_net_context *) ctx)->fd;
- int error = 0;
-
if ( fd < 0 ) {
return ( MBEDTLS_ERR_NET_INVALID_CONTEXT );
}
ret = (int) write( fd, buf, len );
if ( ret < 0 ) {
- if ( net_would_block( ctx, &error ) != 0 ) {
+ if ( net_would_block( ctx ) != 0 ) {
return ( MBEDTLS_ERR_SSL_WANT_WRITE );
}
- if ( error == EPIPE || error == ECONNRESET ) {
+ if ( errno == EPIPE || errno == ECONNRESET ) {
return ( MBEDTLS_ERR_NET_CONN_RESET );
}
- if ( error == EINTR ) {
+ if ( errno == EINTR ) {
return ( MBEDTLS_ERR_SSL_WANT_WRITE );
}