diff --git a/examples/client.c b/examples/client.c index e3286413..f00eb333 100644 --- a/examples/client.c +++ b/examples/client.c @@ -1326,7 +1326,9 @@ main(int argc, char **argv) { while ( !(ready && coap_can_exit(ctx)) ) { - result = coap_run_once( ctx, wait_ms == 0 ? obs_ms : obs_ms == 0 ? wait_ms : min( wait_ms, obs_ms ) ); + result = coap_run_once( ctx, wait_ms == 0 ? + obs_ms : obs_ms == 0 ? + min(wait_ms, 1000) : min( wait_ms, obs_ms ) ); if ( result >= 0 ) { if ( wait_ms > 0 && !wait_ms_reset ) { diff --git a/include/coap/coap_session.h b/include/coap/coap_session.h index f3f4b54c..f0bcc962 100644 --- a/include/coap/coap_session.h +++ b/include/coap/coap_session.h @@ -83,6 +83,7 @@ typedef struct coap_session_t { unsigned int max_retransmit; /**< maximum re-transmit count (default 4) */ coap_fixed_point_t ack_timeout; /**< timeout waiting for ack (default 2 secs) */ coap_fixed_point_t ack_random_factor; /**< ack random factor backoff (default 1.5) */ + unsigned int dtls_timeout_count; /**mtu); + session->dtls_timeout_count = 0; + r = SSL_connect(ssl); if (r == -1) { int ret = SSL_get_error(ssl, r); @@ -835,7 +837,9 @@ void coap_dtls_handle_timeout(coap_session_t *session) { SSL *ssl = (SSL *)session->tls; assert(ssl != NULL); - if (DTLSv1_handle_timeout(ssl) < 0) { + if (((session->state == COAP_SESSION_STATE_HANDSHAKE) && + (++session->dtls_timeout_count > session->max_retransmit)) || + (DTLSv1_handle_timeout(ssl) < 0)) { /* Too many retries */ coap_session_disconnected(session, COAP_NACK_TLS_FAILED); }