coap_write_session: Account correctly for partial TCP writes

Fix the buffer start offset when writing the next part of the PDU.

Also correctly report the number of bytes actually written,
This commit is contained in:
Jon Shallow committed 2021-11-29 15:59:17 +00:00
1 parent df9071c93e
commit bdf7686613
2 files changed
+2 -2

No files matched your search

+1 -1
View File
@@ -325,7 +325,7 @@ ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t
if (bytes_written > 0) {
coap_ticks(&session->last_rx_tx);
coap_log(LOG_DEBUG, "* %s: sent %zd bytes\n",
coap_session_str(session), datalen);
coap_session_str(session), bytes_written);
} else if (bytes_written < 0) {
coap_log(LOG_DEBUG, "* %s: failed to send %zd bytes\n",
coap_session_str(session), datalen );
+1 -1
View File
@@ -1487,7 +1487,7 @@ coap_write_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now
#if !COAP_DISABLE_TCP
bytes_written = coap_session_write(
session,
q->pdu->token - q->pdu->hdr_size - session->partial_write,
q->pdu->token - q->pdu->hdr_size + session->partial_write,
q->pdu->used_size + q->pdu->hdr_size - session->partial_write
);
#endif /* !COAP_DISABLE_TCP */