coap_session, net.c: Add debug messages on TCP RX/TX.

This commit is contained in:
jcmichelou committed 2017-10-21 16:11:14 +02:00
1 parent 6bf4856e4c
commit 9bb8396b23
3 files changed
+38 -6

No files matched your search

+19 -2
View File
@@ -198,8 +198,9 @@ coap_session_t *coap_new_server_session(
);
/**
* Function interface for data transmission. This function returns the number of
* bytes that have been transmitted, or a value less than zero on error.
* Function interface for datagram data transmission. This function returns
* the number of bytes that have been transmitted, or a value less than zero
* on error.
*
* @param session Session to send data on.
* @param data The data to send.
@@ -211,6 +212,22 @@ coap_session_t *coap_new_server_session(
ssize_t coap_session_send(coap_session_t *session,
const uint8_t *data, size_t datalen);
/**
* Function interface for stream data transmission. This function returns
* the number of bytes that have been transmitted, or a value less than zero
* on error. The number of bytes written may be less than datalen because of
* congestion control.
*
* @param session Session to send data on.
* @param data The data to send.
* @param datalen The actual length of @p data.
*
* @return The number of bytes written on success, or a value
* less than zero on error.
*/
ssize_t coap_session_write(coap_session_t *session,
const uint8_t *data, size_t datalen);
/**
* Send a pdu according to the session's protocol. This function returns
* the number of bytes that have been transmitted, or a value less than zero
+11
View File
@@ -180,6 +180,17 @@ ssize_t coap_session_send(coap_session_t *session, const uint8_t *data, size_t d
return bytes_written;
}
ssize_t coap_session_write(coap_session_t *session, const uint8_t *data, size_t datalen) {
ssize_t bytes_written = coap_socket_write(&session->sock, data, datalen);
if (bytes_written > 0) {
coap_ticks(&session->last_rx_tx);
debug("* %s: sent %zd bytes\n", coap_session_str(session), datalen);
} else if (bytes_written < 0) {
debug( "* %s: failed to send %zd bytes\n", coap_session_str(session), datalen );
}
return bytes_written;
}
ssize_t
coap_session_delay_pdu(coap_session_t *session, coap_pdu_t *pdu,
coap_queue_t *node)
+8 -4
View File
@@ -643,8 +643,8 @@ coap_session_send_pdu(coap_session_t *session, coap_pdu_t *pdu) {
pdu->used_size + pdu->hdr_size);
break;
case COAP_PROTO_TCP:
bytes_written = coap_socket_write(&session->sock,
pdu->token - pdu->hdr_size, pdu->used_size + pdu->hdr_size);
bytes_written = coap_session_write(session, pdu->token - pdu->hdr_size,
pdu->used_size + pdu->hdr_size);
break;
case COAP_PROTO_TLS:
bytes_written = coap_tls_write(session, pdu->token - pdu->hdr_size,
@@ -1018,8 +1018,8 @@ coap_write_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now
assert(session->partial_write < q->pdu->used_size + q->pdu->hdr_size);
switch (session->proto) {
case COAP_PROTO_TCP:
bytes_written = coap_socket_write(
&session->sock,
bytes_written = coap_session_write(
session,
q->pdu->token - q->pdu->hdr_size - session->partial_write,
q->pdu->used_size + q->pdu->hdr_size - session->partial_write
);
@@ -1088,6 +1088,10 @@ coap_read_session(coap_context_t *ctx, coap_session_t *session, coap_tick_t now)
bytes_read = coap_socket_read(&session->sock, buf, buf_len);
else if (session->proto == COAP_PROTO_TLS)
bytes_read = coap_tls_read(session, buf, buf_len);
if (bytes_read > 0) {
debug("* %s: received %zd bytes\n", coap_session_str(session), bytes_read);
session->last_rx_tx = now;
}
p = buf;
retry = bytes_read == buf_len;
while (bytes_read > 0) {