mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-10 20:25:47 +00:00
Clean up idle() function in ssl_client2 and ssl_server2
This commit is contained in:
parent
df4180a235
commit
197a91cd82
|
@ -444,20 +444,14 @@ static int ssl_sig_hashes_for_test[] = {
|
||||||
* (Used in event-driven IO mode).
|
* (Used in event-driven IO mode).
|
||||||
*/
|
*/
|
||||||
#if !defined(MBEDTLS_TIMING_C)
|
#if !defined(MBEDTLS_TIMING_C)
|
||||||
void idle( mbedtls_ssl_context *ssl,
|
void idle( mbedtls_net_context *fd,
|
||||||
mbedtls_net_context *fd,
|
|
||||||
int idle_reason )
|
int idle_reason )
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
void idle( mbedtls_ssl_context *ssl,
|
void idle( mbedtls_net_context *fd,
|
||||||
mbedtls_net_context *fd,
|
|
||||||
mbedtls_timing_delay_context *timer,
|
mbedtls_timing_delay_context *timer,
|
||||||
int idle_reason )
|
int idle_reason )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_DEBUG_C)
|
|
||||||
struct mbedtls_timing_hr_time tm;
|
|
||||||
unsigned long time_elapsed;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int poll_type = 0;
|
int poll_type = 0;
|
||||||
|
@ -468,43 +462,24 @@ void idle( mbedtls_ssl_context *ssl,
|
||||||
poll_type = MBEDTLS_NET_POLL_READ;
|
poll_type = MBEDTLS_NET_POLL_READ;
|
||||||
#if !defined(MBEDTLS_TIMING_C)
|
#if !defined(MBEDTLS_TIMING_C)
|
||||||
else
|
else
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "WARNING: No reason for idling given" ) );
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* One should not idle on the underlying transport
|
|
||||||
* if data is still pending to be processed. */
|
|
||||||
if( mbedtls_ssl_check_pending( ssl ) != 0 )
|
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "WARNING: Data still pending, but idling requested!" ) );
|
|
||||||
}
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "idle, waiting for event... " ) );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_TIMING_C) && defined(MBEDTLS_DEBUG_C)
|
|
||||||
mbedtls_timing_get_timer( &tm, 1 /* restart */ );
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
/* Check if timer has expired */
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
#if defined(MBEDTLS_DEBUG_C)
|
if( timer != NULL &&
|
||||||
time_elapsed = mbedtls_timing_get_timer( &tm, 0 );
|
mbedtls_timing_get_delay( timer ) == 2 )
|
||||||
#endif
|
|
||||||
if( mbedtls_timing_get_delay( timer ) == 2 )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "[%lu ms] timer expired - continue",
|
|
||||||
time_elapsed ) );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* MBEDTLS_TIMING_C */
|
||||||
|
|
||||||
|
/* Check if underlying transport became available */
|
||||||
if( poll_type != 0 &&
|
if( poll_type != 0 &&
|
||||||
mbedtls_net_poll( fd, poll_type, 0 ) == poll_type )
|
mbedtls_net_poll( fd, poll_type, 0 ) == poll_type )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "[%lu ms] net_context signals data - continue",
|
|
||||||
time_elapsed ) );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1532,9 +1507,9 @@ int main( int argc, char *argv[] )
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1629,9 +1604,9 @@ int main( int argc, char *argv[] )
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1693,9 +1668,9 @@ send_request:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1715,9 +1690,9 @@ send_request:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1761,9 +1736,9 @@ send_request:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -1822,9 +1797,9 @@ send_request:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1887,9 +1862,9 @@ send_request:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &server_fd, &timer, ret );
|
idle( &server_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &server_fd, ret );
|
idle( &server_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -846,20 +846,14 @@ static int ssl_sig_hashes_for_test[] = {
|
||||||
* (Used in event-driven IO mode).
|
* (Used in event-driven IO mode).
|
||||||
*/
|
*/
|
||||||
#if !defined(MBEDTLS_TIMING_C)
|
#if !defined(MBEDTLS_TIMING_C)
|
||||||
void idle( mbedtls_ssl_context *ssl,
|
void idle( mbedtls_net_context *fd,
|
||||||
mbedtls_net_context *fd,
|
|
||||||
int idle_reason )
|
int idle_reason )
|
||||||
{
|
{
|
||||||
#else
|
#else
|
||||||
void idle( mbedtls_ssl_context *ssl,
|
void idle( mbedtls_net_context *fd,
|
||||||
mbedtls_net_context *fd,
|
|
||||||
mbedtls_timing_delay_context *timer,
|
mbedtls_timing_delay_context *timer,
|
||||||
int idle_reason )
|
int idle_reason )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_DEBUG_C)
|
|
||||||
struct mbedtls_timing_hr_time tm;
|
|
||||||
unsigned long time_elapsed;
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int poll_type = 0;
|
int poll_type = 0;
|
||||||
|
@ -870,44 +864,24 @@ void idle( mbedtls_ssl_context *ssl,
|
||||||
poll_type = MBEDTLS_NET_POLL_READ;
|
poll_type = MBEDTLS_NET_POLL_READ;
|
||||||
#if !defined(MBEDTLS_TIMING_C)
|
#if !defined(MBEDTLS_TIMING_C)
|
||||||
else
|
else
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "WARNING: No reason for idling given" ) );
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* One should not idle on the underlying transport
|
|
||||||
* if data is still pending to be processed. */
|
|
||||||
if( mbedtls_ssl_check_pending( ssl ) != 0 )
|
|
||||||
{
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "WARNING: Data still pending, "
|
|
||||||
"but idling requested!" ) );
|
|
||||||
}
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "idle, waiting for event... " ) );
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_TIMING_C) && defined(MBEDTLS_DEBUG_C)
|
|
||||||
mbedtls_timing_get_timer( &tm, 1 /* restart */ );
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
/* Check if timer has expired */
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
#if defined(MBEDTLS_DEBUG_C)
|
if( timer != NULL &&
|
||||||
time_elapsed = mbedtls_timing_get_timer( &tm, 0 );
|
mbedtls_timing_get_delay( timer ) == 2 )
|
||||||
#endif
|
|
||||||
if( mbedtls_timing_get_delay( timer ) == 2 )
|
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "[%lu ms] timer expired - continue",
|
|
||||||
time_elapsed ) );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* MBEDTLS_TIMING_C */
|
||||||
|
|
||||||
|
/* Check if underlying transport became available */
|
||||||
if( poll_type != 0 &&
|
if( poll_type != 0 &&
|
||||||
mbedtls_net_poll( fd, poll_type, 0 ) == poll_type )
|
mbedtls_net_poll( fd, poll_type, 0 ) == poll_type )
|
||||||
{
|
{
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "[%lu ms] net_context signals data - "
|
|
||||||
"continue", time_elapsed ) );
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2231,9 +2205,9 @@ handshake:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &client_fd, &timer, ret );
|
idle( &client_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &client_fd, ret );
|
idle( &client_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2346,9 +2320,9 @@ data_exchange:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &client_fd, &timer, ret );
|
idle( &client_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &client_fd, ret );
|
idle( &client_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2453,9 +2427,9 @@ data_exchange:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &client_fd, &timer, ret );
|
idle( &client_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &client_fd, ret );
|
idle( &client_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2504,9 +2478,9 @@ data_exchange:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &client_fd, &timer, ret );
|
idle( &client_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &client_fd, ret );
|
idle( &client_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2548,9 +2522,9 @@ data_exchange:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &client_fd, &timer, ret );
|
idle( &client_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &client_fd, ret );
|
idle( &client_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2570,9 +2544,9 @@ data_exchange:
|
||||||
if( opt.event == 1 /* level triggered IO */ )
|
if( opt.event == 1 /* level triggered IO */ )
|
||||||
{
|
{
|
||||||
#if defined(MBEDTLS_TIMING_C)
|
#if defined(MBEDTLS_TIMING_C)
|
||||||
idle( &ssl, &client_fd, &timer, ret );
|
idle( &client_fd, &timer, ret );
|
||||||
#else
|
#else
|
||||||
idle( &ssl, &client_fd, ret );
|
idle( &client_fd, ret );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue