Split ssl_set_read_timeout() out of bio_timeout()
This commit is contained in:
parent
cc3195e81f
commit
97fd52c529
@ -1298,7 +1298,6 @@ void mbedtls_ssl_set_bio( mbedtls_ssl_context *ssl,
|
||||
* \param f_recv read callback
|
||||
* \param f_recv_timeout read callback with timeout.
|
||||
* The last argument of the callback is the timeout in seconds
|
||||
* \param timeout value of the mbedtls_ssl_read() timeout in milliseconds
|
||||
*
|
||||
* \note f_recv_timeout is required for DTLS, unless f_recv performs
|
||||
* non-blocking reads.
|
||||
@ -1309,8 +1308,20 @@ void mbedtls_ssl_set_bio_timeout( mbedtls_ssl_context *ssl,
|
||||
void *p_bio,
|
||||
int (*f_send)(void *, const unsigned char *, size_t),
|
||||
int (*f_recv)(void *, unsigned char *, size_t),
|
||||
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t),
|
||||
uint32_t timeout );
|
||||
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) );
|
||||
|
||||
/**
|
||||
* \brief Set the timeout period for mbedtls_ssl_read()
|
||||
* (Default: no timeout.)
|
||||
*
|
||||
* \param conf SSL configuration context
|
||||
* \param timeout Timeout value in milliseconds.
|
||||
* Use 0 for no timeout (default).
|
||||
*
|
||||
* \note With blocking I/O, this will only work if a non-NULL
|
||||
* \c f_recv_timeout was set with \c mbedtls_ssl_set_bio_timeout().
|
||||
*/
|
||||
void mbedtls_ssl_set_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout );
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
|
||||
/**
|
||||
|
@ -5249,14 +5249,17 @@ void mbedtls_ssl_set_bio_timeout( mbedtls_ssl_context *ssl,
|
||||
void *p_bio,
|
||||
int (*f_send)(void *, const unsigned char *, size_t),
|
||||
int (*f_recv)(void *, unsigned char *, size_t),
|
||||
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t),
|
||||
uint32_t timeout )
|
||||
int (*f_recv_timeout)(void *, unsigned char *, size_t, uint32_t) )
|
||||
{
|
||||
ssl->p_bio = p_bio;
|
||||
ssl->f_send = f_send;
|
||||
ssl->f_recv = f_recv;
|
||||
ssl->f_recv_timeout = f_recv_timeout;
|
||||
ssl->conf->read_timeout = timeout;
|
||||
}
|
||||
|
||||
void mbedtls_ssl_set_read_timeout( mbedtls_ssl_config *conf, uint32_t timeout )
|
||||
{
|
||||
conf->read_timeout = timeout;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_SRV_C)
|
||||
|
@ -191,8 +191,7 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_ssl_set_dbg( &conf, my_debug, stdout );
|
||||
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd,
|
||||
mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout,
|
||||
READ_TIMEOUT_MS );
|
||||
mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout );
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
|
@ -280,8 +280,7 @@ reset:
|
||||
}
|
||||
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd,
|
||||
mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout,
|
||||
READ_TIMEOUT_MS );
|
||||
mbedtls_net_send, mbedtls_net_recv, mbedtls_net_recv_timeout );
|
||||
|
||||
printf( " ok\n" );
|
||||
|
||||
|
@ -250,7 +250,7 @@ int main( void )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
if( mbedtls_ssl_handshake( &ssl ) != 0 )
|
||||
{
|
||||
|
@ -178,7 +178,7 @@ int main( void )
|
||||
|
||||
mbedtls_ssl_set_rng( &ssl, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
mbedtls_ssl_set_dbg( &conf, my_debug, stdout );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
/*
|
||||
* 4. Handshake
|
||||
|
@ -1119,16 +1119,16 @@ int main( int argc, char *argv[] )
|
||||
mbedtls_ssl_set_dbg( &conf, my_debug, stdout );
|
||||
|
||||
if( opt.nbio == 2 )
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, my_send, my_recv, NULL,
|
||||
opt.read_timeout );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, my_send, my_recv, NULL );
|
||||
else
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv,
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL,
|
||||
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL
|
||||
#else
|
||||
NULL,
|
||||
NULL
|
||||
#endif
|
||||
opt.read_timeout );
|
||||
);
|
||||
mbedtls_ssl_set_read_timeout( &conf, opt.read_timeout );
|
||||
|
||||
#if defined(MBEDTLS_SSL_SESSION_TICKETS)
|
||||
if( ( ret = mbedtls_ssl_set_session_tickets( &conf, opt.tickets ) ) != 0 )
|
||||
|
@ -267,7 +267,7 @@ int main( void )
|
||||
|
||||
mbedtls_ssl_set_rng( &ssl, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
mbedtls_ssl_set_dbg( &conf, my_debug, stdout );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
mbedtls_ssl_set_ca_chain( &conf, srvcert.next, NULL );
|
||||
if( ( ret = mbedtls_ssl_set_own_cert( &ssl, &srvcert, &pkey ) ) != 0 )
|
||||
|
@ -606,7 +606,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
mbedtls_ssl_set_rng( &ssl, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
mbedtls_ssl_set_dbg( &conf, my_debug, stdout );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
if( opt.force_ciphersuite[0] != DFL_FORCE_CIPHER )
|
||||
mbedtls_ssl_set_ciphersuites( &conf, opt.force_ciphersuite );
|
||||
|
@ -197,7 +197,7 @@ static void *handle_ssl_connection( void *data )
|
||||
|
||||
mbedtls_printf( " [ #%d ] ok\n", thread_id );
|
||||
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
mbedtls_printf( " [ #%d ] ok\n", thread_id );
|
||||
|
||||
|
@ -252,7 +252,7 @@ reset:
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
mbedtls_printf( " ok\n" );
|
||||
|
||||
|
@ -1819,15 +1819,16 @@ reset:
|
||||
}
|
||||
|
||||
if( opt.nbio == 2 )
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, my_send, my_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, my_send, my_recv, NULL );
|
||||
else
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &client_fd, mbedtls_net_send, mbedtls_net_recv,
|
||||
#if defined(MBEDTLS_HAVE_TIME)
|
||||
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL,
|
||||
opt.nbio == 0 ? mbedtls_net_recv_timeout : NULL
|
||||
#else
|
||||
NULL,
|
||||
NULL
|
||||
#endif
|
||||
opt.read_timeout );
|
||||
);
|
||||
mbedtls_ssl_set_read_timeout( &conf, opt.read_timeout );
|
||||
|
||||
#if defined(MBEDTLS_SSL_DTLS_HELLO_VERIFY)
|
||||
if( opt.transport == MBEDTLS_SSL_TRANSPORT_DATAGRAM )
|
||||
|
@ -421,7 +421,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
mbedtls_ssl_set_rng( &ssl, mbedtls_ctr_drbg_random, &ctr_drbg );
|
||||
mbedtls_ssl_set_dbg( &conf, my_debug, stdout );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL, 0 );
|
||||
mbedtls_ssl_set_bio_timeout( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
|
||||
|
||||
if( ( ret = mbedtls_ssl_set_own_cert( &ssl, &clicert, &pkey ) ) != 0 )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user