Advertisement
cerr_

mbedtls_tls_recv_timeout

Jun 7th, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. int mbedtls_tls_recv_timeout( void *ctx, unsigned char *buf, size_t len,
  2.                       uint32_t timeout )
  3. {
  4.     int ret, err;
  5.     struct timeval tv;
  6.     fd_set read_fds;
  7.  
  8.     struct fns_timeval  tv_fns;
  9.     fns_fd_set          read_fds_fns;
  10.  
  11.     int fd = ((mbedtls_net_context *) ctx)->fd;
  12.  
  13.     if( fd < 0 )
  14.         return( MBEDTLS_ERR_NET_INVALID_CONTEXT );
  15.  
  16.     if(ipv6)
  17.     {
  18.         FD_ZERO( &read_fds_fns );
  19.         FD_SET( fd, &read_fds_fns );
  20.         tv_fns.tv_sec  = 10;
  21.         tv_fns.tv_usec = 0;
  22.         ret = fnsSelect( fd + 1, &read_fds_fns, NULL, NULL, &tv_fns, (int*)&err );
  23.     }
  24.     else
  25.     {
  26.         FD_ZERO( &read_fds );
  27.         FD_SET( fd, &read_fds );
  28.         tv.tv_sec  = 10;
  29.         tv.tv_usec = 0;
  30.         ret = select( fd + 1, &read_fds, NULL, NULL, &tv );
  31.     }
  32.  
  33.     /* Zero fds ready means we timed out */
  34.     if( ret == 0 ) {
  35.         FTP_DEBUG0("mbedtls_tls_recv_timeout :: timed out\n");
  36.         return( MBEDTLS_ERR_SSL_TIMEOUT );
  37.     }
  38.  
  39.     if( ret < 0 )
  40.     {
  41. #if ( defined(_WIN32) || defined(_WIN32_WCE) ) && !defined(EFIX64) && \
  42.     !defined(EFI32)
  43.         if( WSAGetLastError() == WSAEINTR )
  44.             return( MBEDTLS_ERR_SSL_WANT_READ );
  45. #else
  46.         if( errno == EINTR )
  47.             return( MBEDTLS_ERR_SSL_WANT_READ );
  48. #endif
  49.  
  50.         return( MBEDTLS_ERR_NET_RECV_FAILED );
  51.     }
  52.  
  53.     /* This call will not block */
  54.     return( mbedtls_tls_recv( ctx, buf, len ) );
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement