From a0f94fe2de33dee58149c6f64c34f2f7bf85eea8 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Thu, 26 Jul 2018 14:06:37 +0100 Subject: [PATCH] Rename coap_session_t sendqueue variable to delayqueue This better describes what is going on here (as they are created by coap_session_delay_pdu() and are only released off this queue when either the session becomes established, or the outstanding CON requests falls below COAP_DEFAULT_NSTART (a value of 1). This is to remove confusion with the use of coap_context_t sendqueue which is used for retransmitting data after no response detected for a CON request. include/coap/coap_session.h src/coap_io.c src/coap_session.c src/net.c --- include/coap/coap_session.h | 2 +- src/coap_io.c | 7 +++++-- src/coap_session.c | 30 +++++++++++++++--------------- src/net.c | 10 +++++----- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/include/coap/coap_session.h b/include/coap/coap_session.h index 3645be9d..00fc50f5 100644 --- a/include/coap/coap_session.h +++ b/include/coap/coap_session.h @@ -69,7 +69,7 @@ typedef struct coap_session_t { void *tls; /**< security parameters */ uint16_t tx_mid; /**< the last message id that was used in this session */ uint8_t con_active; /**< Active CON request sent */ - struct coap_queue_t *sendqueue; /**< list of messages waiting to be sent */ + struct coap_queue_t *delayqueue; /**< list of delayed messages waiting to be sent */ size_t partial_write; /**< if > 0 indicates number of bytes already written from the pdu at the head of sendqueue */ uint8_t read_header[8]; /**< storage space for header of incoming message header */ size_t partial_read; /**< if > 0 indicates number of bytes already read for an incoming message */ diff --git a/src/coap_io.c b/src/coap_io.c index 27a12b9b..d378024a 100644 --- a/src/coap_io.c +++ b/src/coap_io.c @@ -1077,10 +1077,13 @@ coap_write(coap_context_t *ctx, sockets[(*num_sockets)++] = &ep->sock; } LL_FOREACH_SAFE(ep->sessions, s, tmp) { - if (s->type == COAP_SESSION_TYPE_SERVER && s->ref == 0 && s->sendqueue == NULL && (s->last_rx_tx + session_timeout <= now || s->state == COAP_SESSION_STATE_NONE)) { + if (s->type == COAP_SESSION_TYPE_SERVER && s->ref == 0 && + s->delayqueue == NULL && + (s->last_rx_tx + session_timeout <= now || + s->state == COAP_SESSION_STATE_NONE)) { coap_session_free(s); } else { - if (s->type == COAP_SESSION_TYPE_SERVER && s->ref == 0 && s->sendqueue == NULL) { + if (s->type == COAP_SESSION_TYPE_SERVER && s->ref == 0 && s->delayqueue == NULL) { coap_tick_t s_timeout = (s->last_rx_tx + session_timeout) - now; if (timeout == 0 || s_timeout < timeout) timeout = s_timeout; diff --git a/src/coap_session.c b/src/coap_session.c index 340a36fc..e37c72f2 100644 --- a/src/coap_session.c +++ b/src/coap_session.c @@ -170,7 +170,7 @@ void coap_session_free(coap_session_t *session) { if (session->psk_key) coap_free(session->psk_key); - LL_FOREACH_SAFE(session->sendqueue, q, tmp) { + LL_FOREACH_SAFE(session->delayqueue, q, tmp) { if (q->pdu->type==COAP_MESSAGE_CON && session->context && session->context->nack_handler) session->context->nack_handler(session->context, session, q->pdu, session->proto == COAP_PROTO_DTLS ? COAP_NACK_TLS_FAILED : COAP_NACK_NOT_DELIVERABLE, q->id); coap_delete_node(q); @@ -254,7 +254,7 @@ coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, } else { coap_queue_t *q = NULL; /* Check that the same tid is not getting re-used in violation of RFC7252 */ - LL_FOREACH(session->sendqueue, q) { + LL_FOREACH(session->delayqueue, q) { if (q->id == pdu->tid) { coap_log(LOG_ERR, "** %s tid=%d: already in-use - dropped\n", coap_session_str(session), pdu->tid); return COAP_INVALID_TID; @@ -272,7 +272,7 @@ coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu, node->timeout = coap_calc_timeout(session, r); } } - LL_APPEND(session->sendqueue, node); + LL_APPEND(session->delayqueue, node); debug("** %s tid=%d: delayed\n", coap_session_str(session), node->id); return COAP_PDU_DELAYED; } @@ -318,10 +318,10 @@ void coap_session_connected(coap_session_t *session) { } } - while (session->sendqueue && session->state == COAP_SESSION_STATE_ESTABLISHED) { + while (session->delayqueue && session->state == COAP_SESSION_STATE_ESTABLISHED) { ssize_t bytes_written; - coap_queue_t *q = session->sendqueue; - session->sendqueue = q->next; + coap_queue_t *q = session->delayqueue; + session->delayqueue = q->next; q->next = NULL; if (q->pdu->type == COAP_MESSAGE_CON && COAP_PROTO_NOT_RELIABLE(session->proto)) { if (session->con_active >= COAP_DEFAULT_NSTART) @@ -342,8 +342,8 @@ void coap_session_connected(coap_session_t *session) { break; } else { if (bytes_written <= 0 || (size_t)bytes_written < q->pdu->used_size + q->pdu->hdr_size) { - q->next = session->sendqueue; - session->sendqueue = q; + q->next = session->delayqueue; + session->delayqueue = q; if (bytes_written > 0) session->partial_write = (size_t)bytes_written; break; @@ -373,9 +373,9 @@ void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reaso } session->partial_read = 0; if (COAP_PROTO_NOT_RELIABLE(session->proto)) { - while (session->sendqueue) { - coap_queue_t *q = session->sendqueue; - session->sendqueue = q->next; + while (session->delayqueue) { + coap_queue_t *q = session->delayqueue; + session->delayqueue = q->next; q->next = NULL; debug("** %s tid=%d: not transmitted after delay\n", coap_session_str(session), q->id); if (q->pdu->type==COAP_MESSAGE_CON && COAP_PROTO_NOT_RELIABLE(session->proto)) { @@ -414,9 +414,9 @@ void coap_session_reset(coap_session_t *session) { session->partial_pdu = NULL; } session->partial_read = 0; - while (session->sendqueue) { - coap_queue_t *q = session->sendqueue; - session->sendqueue = q->next; + while (session->delayqueue) { + coap_queue_t *q = session->delayqueue; + session->delayqueue = q->next; q->next = NULL; debug("** %s tid=%d: not transmitted after delay\n", coap_session_str(session), (int)q->id); if (q->pdu->type == COAP_MESSAGE_CON && session->context->nack_handler) @@ -442,7 +442,7 @@ coap_endpoint_get_session(coap_endpoint_t *endpoint, session->last_rx_tx = now; return session; } - if (session->ref == 0 && session->sendqueue == NULL && session->type == COAP_SESSION_TYPE_SERVER) { + if (session->ref == 0 && session->delayqueue == NULL && session->type == COAP_SESSION_TYPE_SERVER) { ++num_idle; if (oldest==NULL || session->last_rx_tx < oldest->last_rx_tx) oldest = session; diff --git a/src/net.c b/src/net.c index 0ed70f5e..d0294376 100644 --- a/src/net.c +++ b/src/net.c @@ -1031,9 +1031,9 @@ coap_write_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now (void)ctx; assert(session->sock.flags & COAP_SOCKET_CONNECTED); - while (session->sendqueue) { + while (session->delayqueue) { ssize_t bytes_written; - coap_queue_t *q = session->sendqueue; + coap_queue_t *q = session->delayqueue; debug("** %s tid=%d: transmitted after delay\n", coap_session_str(session), (int)q->pdu->tid); assert(session->partial_write < q->pdu->used_size + q->pdu->hdr_size); switch (session->proto) { @@ -1062,7 +1062,7 @@ coap_write_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now session->partial_write += (size_t)bytes_written; break; } - session->sendqueue = q->next; + session->delayqueue = q->next; session->partial_write = 0; coap_delete_node(q); } @@ -2232,12 +2232,12 @@ coap_can_exit(coap_context_t *context) { return 0; LL_FOREACH(context->endpoint, ep) { LL_FOREACH(ep->sessions, s) { - if (s->sendqueue) + if (s->delayqueue) return 0; } } LL_FOREACH(context->sessions, s) { - if (s->sendqueue) + if (s->delayqueue) return 0; } return 1;