diff --git a/include/nuttx/net/iob.h b/include/nuttx/net/iob.h index 1c0e2b338d..25dbbc39a7 100644 --- a/include/nuttx/net/iob.h +++ b/include/nuttx/net/iob.h @@ -304,7 +304,8 @@ int iob_contig(FAR struct iob_s *iob, unsigned int len); ****************************************************************************/ #ifdef CONFIG_DEBUG -void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len); +void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len, + unsigned int offset); #else # define iob_dump(wrb) #endif diff --git a/include/nuttx/net/uip/uip-arch.h b/include/nuttx/net/uip/uip-arch.h index c6b664d7f7..905af0c507 100644 --- a/include/nuttx/net/uip/uip-arch.h +++ b/include/nuttx/net/uip/uip-arch.h @@ -163,7 +163,7 @@ struct uip_driver_s uint16_t d_len; - /* When d_buf contains outgoing xmit data, xmtlen is nonzero and represents + /* When d_buf contains outgoing xmit data, d_sndlen is nonzero and represents * the amount of appllcation data after d_snddata */ diff --git a/include/nuttx/net/uip/uip-tcp.h b/include/nuttx/net/uip/uip-tcp.h index f1ccf67dc5..b1e0fac2ff 100644 --- a/include/nuttx/net/uip/uip-tcp.h +++ b/include/nuttx/net/uip/uip-tcp.h @@ -139,9 +139,10 @@ do { (wrb)->wb_iob = iob_trimhead((wrb)->wb_iob,(n)); } while (0) #ifdef CONFIG_DEBUG -# define WRB_DUMP(msg,wrb,len) tcp_wrbuffer_dump(msg,wrb,len) +# define WRB_DUMP(msg,wrb,len,offset) \ + tcp_wrbuffer_dump(msg,wrb,len,offset) #else -# define WRB_DUMP(msg,wrb,len) +# define WRB_DUMP(msg,wrb,len,offset) #endif #endif diff --git a/net/iob/iob_dump.c b/net/iob/iob_dump.c index d767057405..ee7cda4e3a 100644 --- a/net/iob/iob_dump.c +++ b/net/iob/iob_dump.c @@ -82,37 +82,68 @@ * ****************************************************************************/ -void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len) +void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len, + unsigned int offset) { + FAR struct iob_s *head; uint8_t data[32]; + unsigned int maxlen; unsigned int nbytes; - unsigned int i; - unsigned int j; + unsigned int lndx; + unsigned int cndx; - message("%s: iob=%p len = %d pktlen=%d\n", msg, iob, len, iob->io_pktlen); - len = MIN(len, iob->io_pktlen); + head = iob; + message("%s: iob=%p pktlen=%d\n", msg, head, head->io_pktlen); - for (i = 0; i < len; i += 32) + /* Check if the offset is beyond the data in the I/O buffer chain */ + + if (offset > head->io_pktlen) { - /* Copy 32-bytes into our local buffer */ + ndbg("ERROR: offset is past the end of data: %u > %u\n", + offset, head->io_pktlen); + return; + } - nbytes = iob_copyout(data, iob, 32, i); + /* Dump I/O buffer headers */ + + for (; iob; iob = iob->io_flink) + { + message(" iob=%p len=%d offset=%d\n", iob, iob->io_len, iob->io_offset); + } + + /* Get the amount of data to be displayed, limited by the amount that we + * have beyond the offset. + */ + + maxlen = head->io_pktlen - offset; + len = MIN(len, maxlen); + + /* Then beginning printing with the buffer containing the offset in groups + * of 32 bytes. + */ + + for (lndx = 0; lndx < len; lndx += 32, offset += 32) + { + /* Copy 32-bytes into our local buffer from the current offset */ + + nbytes = iob_copyout(data, head, 32, offset); /* Make sure that we have something to print */ if (nbytes > 0) { - message("%04x: ", i); - for (j = 0; j < 32; j++) + message(" %04x: ", offset); + + for (cndx = 0; cndx < 32; cndx++) { - if (j == 16) + if (cndx == 16) { message(" "); } - if (i + j < len) + if ((lndx + cndx) < len) { - message("%02x", data[j]); + message("%02x", data[cndx]); } else { @@ -121,18 +152,18 @@ void iob_dump(FAR const char *msg, FAR struct iob_s *iob, unsigned int len) } message(" "); - for (j = 0; j < 32; j++) + for (cndx = 0; cndx < 32; cndx++) { - if (j == 16) + if (cndx == 16) { message(" "); } - if (i + j < len) + if ((lndx + cndx) < len) { - if (data[j] >= 0x20 && data[j] < 0x7f) + if (data[cndx] >= 0x20 && data[cndx] < 0x7f) { - message("%c", data[j]); + message("%c", data[cndx]); } else { diff --git a/net/net_send_buffered.c b/net/net_send_buffered.c index 1c75f44db9..639b177ca6 100644 --- a/net/net_send_buffered.c +++ b/net/net_send_buffered.c @@ -82,9 +82,9 @@ #ifdef CONFIG_NET_TCP_WRBUFFER_DUMP # define BUF_DUMP(msg,buf,len) lib_dumpbuffer(msg,buf,len) #else -# define BUF_DUMP(msg,buf,len) +# define BUF_DUMP(msg,buf,len,offset) # undef WRB_DUMP -# define WRB_DUMP(msg,wrb,len) +# define WRB_DUMP(msg,wrb,len,offset) #endif /**************************************************************************** @@ -285,12 +285,21 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, */ trimlen = ackno - WRB_SEQNO(wrb); + if (trimlen > WRB_SENT(wrb)) + { + /* More data has been ACKed then we have sent? */ + + trimlen = WRB_SENT(wrb); + } + nllvdbg("ACK: wrb=%p trim %u bytes\n", wrb, trimlen); + WRB_TRIM(wrb, trimlen); + WRB_SEQNO(wrb) = ackno; + WRB_SENT(wrb) -= trimlen; /* Set the new sequence number for what remains */ - WRB_SEQNO(wrb) = ackno; nllvdbg("ACK: wrb=%p seqno=%u pktlen=%u\n", wrb, WRB_SEQNO(wrb), WRB_PKTLEN(wrb)); } @@ -312,7 +321,7 @@ static uint16_t send_interrupt(FAR struct uip_driver_s *dev, FAR void *pvconn, nacked = ackno - WRB_SEQNO(wrb); if (nacked > WRB_SENT(wrb)) { - /* More data has been ACKed then we have sent? */ + /* More data has been ACKed then we have sent? ASSERT? */ nacked = WRB_SENT(wrb); } @@ -793,7 +802,7 @@ ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, /* Dump I/O buffer chain */ - WRB_DUMP("I/O buffer chain", wrb, WRB_PKTLEN(wrb)); + WRB_DUMP("I/O buffer chain", wrb, WRB_PKTLEN(wrb), 0); /* send_interrupt() will send data in FIFO order from the * conn->write_q diff --git a/net/tcp/tcp.h b/net/tcp/tcp.h index f855a8044e..c776e7e478 100644 --- a/net/tcp/tcp.h +++ b/net/tcp/tcp.h @@ -129,7 +129,8 @@ void tcp_wrbuffer_release(FAR struct tcp_wrbuffer_s *wrb); #ifdef CONFIG_NET_TCP_WRITE_BUFFERS #ifdef CONFIG_DEBUG -void tcp_wrbuffer_dump(FAR const char *msg, FAR struct tcp_wrbuffer_s *wrb, unsigned int len); +void tcp_wrbuffer_dump(FAR const char *msg, FAR struct tcp_wrbuffer_s *wrb, + unsigned int len, unsigned int offset); #else # define tcp_wrbuffer_dump(msg,wrb) #endif diff --git a/net/tcp/tcp_wrbuffer_dump.c b/net/tcp/tcp_wrbuffer_dump.c index f91bf20522..6ff5bb0216 100644 --- a/net/tcp/tcp_wrbuffer_dump.c +++ b/net/tcp/tcp_wrbuffer_dump.c @@ -80,11 +80,11 @@ ****************************************************************************/ void tcp_wrbuffer_dump(FAR const char *msg, FAR struct tcp_wrbuffer_s *wrb, - unsigned int len) + unsigned int len, unsigned int offset) { message("%s: wrb=%p segno=%d sent=%d nrtx=%d\n", msg, wrb, WRB_SEQNO(wrb), WRB_SENT(wrb), WRB_NRTX(wrb)); - iob_dump("I/O Buffer Chain", WRB_IOB(wrb), len); + iob_dump("I/O Buffer Chain", WRB_IOB(wrb), len, offset); } #endif /* CONFIG_DEBUG */