mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-10 10:50:40 +03:00
src/coap_io.c: Fix re-transmission delays
There are 2 issues fixed here
Issue 1: In coap_write() (circa line 1074)
if (XXXX && (s->last_rx_tx + session_timeout <= now || YYYY)) {
coap_session_free(s);
} else {
if (XXXX) {
coap_tick_t s_timeout = now - (s->last_rx_tx + session_timeout);
s_timeout will end up as a large number as 'now' is less than
(s->last_rx_tx + session_timeout)
Fix is to reverse the expression
Issue 2: In coap_write() (two places circa lines 1122 and 1136)
If coap_dtls_handle_timeout(s) causes the session to go away,
tls_timeout is set to 0, and so timeout does not get updated (could be 0
and so coap_write() returns 0 causing a wait for the default time in the
select() call.
Fix is to set timeout to 1 to cause a minimal time waiting in the select()
This commit is contained in:
1 parent
4280e75a0c
commit
7afb913ef7
1 file changed
+13
-3
+13
-3
@@ -1071,7 +1071,7 @@ coap_write(coap_context_t *ctx,
|
||||
coap_session_free(s);
|
||||
} else {
|
||||
if (s->type == COAP_SESSION_TYPE_SERVER && s->ref == 0 && s->sendqueue == NULL) {
|
||||
coap_tick_t s_timeout = now - (s->last_rx_tx + session_timeout);
|
||||
coap_tick_t s_timeout = (s->last_rx_tx + session_timeout) - now;
|
||||
if (timeout == 0 || s_timeout < timeout)
|
||||
timeout = s_timeout;
|
||||
}
|
||||
@@ -1119,7 +1119,12 @@ coap_write(coap_context_t *ctx,
|
||||
while (tls_timeout > 0 && tls_timeout <= now) {
|
||||
coap_log(LOG_DEBUG, "** %s: DTLS retransmit timeout\n", coap_session_str(s));
|
||||
coap_dtls_handle_timeout(s);
|
||||
tls_timeout = s->tls ? coap_dtls_get_timeout(s) : 0;
|
||||
if (s->tls)
|
||||
tls_timeout = coap_dtls_get_timeout(s);
|
||||
else {
|
||||
tls_timeout = 0;
|
||||
timeout = 1;
|
||||
}
|
||||
}
|
||||
if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout))
|
||||
timeout = tls_timeout - now;
|
||||
@@ -1133,7 +1138,12 @@ coap_write(coap_context_t *ctx,
|
||||
while (tls_timeout > 0 && tls_timeout <= now) {
|
||||
coap_log(LOG_DEBUG, "** %s: DTLS retransmit timeout\n", coap_session_str(s));
|
||||
coap_dtls_handle_timeout(s);
|
||||
tls_timeout = s->tls ? coap_dtls_get_timeout(s) : 0;
|
||||
if (s->tls)
|
||||
tls_timeout = coap_dtls_get_timeout(s);
|
||||
else {
|
||||
tls_timeout = 0;
|
||||
timeout = 1;
|
||||
}
|
||||
}
|
||||
if (tls_timeout > 0 && (timeout == 0 || tls_timeout - now < timeout))
|
||||
timeout = tls_timeout - now;
|
||||
|
||||
Reference in new issue
Block a user