mirror of
https://github.com/apache/nuttx.git
synced 2026-09-21 05:14:27 +08:00
First cut at conversion of write-buffering to use I/O buffer chaings (IOBs)
This commit is contained in:
+27
-3
@@ -55,10 +55,12 @@
|
||||
#define IOB_DATA(p) (&(p)->io_data[(p)->io_offset])
|
||||
#define IOB_FREESPACE(p) (CONFIG_IOB_BUFSIZE - (p)->io_len - (p)->io_offset)
|
||||
|
||||
#if CONFIG_IOB_NCHAINS > 0
|
||||
/* Queue helpers */
|
||||
|
||||
#define IOB_QINIT(q) do { (q)->qh_head = 0; (q)->qh_tail = 0; } while (0)
|
||||
#define IOB_QEMPTY(q) ((q)->head == NULL)
|
||||
# define IOB_QINIT(q) do { (q)->qh_head = 0; (q)->qh_tail = 0; } while (0)
|
||||
# define IOB_QEMPTY(q) ((q)->head == NULL)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
@@ -89,6 +91,7 @@ struct iob_s
|
||||
uint8_t io_data[CONFIG_IOB_BUFSIZE];
|
||||
};
|
||||
|
||||
#if CONFIG_IOB_NCHAINS > 0
|
||||
/* This container structure supports queuing of I/O buffer chains. This
|
||||
* structure is intended only for internal use by the IOB module.
|
||||
*/
|
||||
@@ -113,6 +116,7 @@ struct iob_queue_s
|
||||
FAR struct iob_qentry_s *qh_head;
|
||||
FAR struct iob_qentry_s *qh_tail;
|
||||
};
|
||||
#endif /* CONFIG_IOB_NCHAINS > 0 */
|
||||
|
||||
/****************************************************************************
|
||||
* Global Data
|
||||
@@ -173,7 +177,9 @@ void iob_free_chain(FAR struct iob_s *iob);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_IOB_NCHAINS > 0
|
||||
int iob_add_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq);
|
||||
#endif /* CONFIG_IOB_NCHAINS > 0 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: iob_add_queue
|
||||
@@ -183,7 +189,9 @@ int iob_add_queue(FAR struct iob_s *iob, FAR struct iob_queue_s *iobq);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_IOB_NCHAINS > 0
|
||||
FAR struct iob_s *iob_remove_queue(FAR struct iob_queue_s *iobq);
|
||||
#endif /* CONFIG_IOB_NCHAINS > 0 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: iob_free_queue
|
||||
@@ -193,7 +201,9 @@ FAR struct iob_s *iob_remove_queue(FAR struct iob_queue_s *iobq);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_IOB_NCHAINS > 0
|
||||
void iob_free_queue(FAR struct iob_queue_s *qhead);
|
||||
#endif /* CONFIG_IOB_NCHAINS > 0 */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: iob_copyin
|
||||
@@ -278,11 +288,25 @@ FAR struct iob_s *iob_pack(FAR struct iob_s *iob);
|
||||
* Name: iob_contig
|
||||
*
|
||||
* Description:
|
||||
* Ensure that there is'len' bytes of contiguous space at the beginning
|
||||
* Ensure that there is 'len' bytes of contiguous space at the beginning
|
||||
* of the I/O buffer chain starting at 'iob'.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int iob_contig(FAR struct iob_s *iob, unsigned int len);
|
||||
|
||||
/****************************************************************************
|
||||
* Function: iob_dump
|
||||
*
|
||||
* Description:
|
||||
* Dump the contents of a I/O buffer chain
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
void iob_dump(FAR const char *msg, FAR struct iob_s *iob);
|
||||
#else
|
||||
# define tcp_writebuffer_dump(wrb)
|
||||
#endif
|
||||
|
||||
#endif /* _INCLUDE_NUTTX_NET_IOB_H */
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <nuttx/net/uip/uipopt.h>
|
||||
#include <nuttx/net/uip/uip.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -123,6 +124,25 @@
|
||||
# define UIP_TCP_INITIAL_MSS UIP_TCP_MSS
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||
/* TCP write buffer access macros */
|
||||
|
||||
# define WRB_SEQNO(wrb) ((wrb)->wb_seqno)
|
||||
# define WRB_PKTLEN(wrb) ((wrb)->wb_iob->io_pktlen)
|
||||
# define WRB_SENT(wrb) ((wrb)->wb_sent)
|
||||
# define WRB_NRTX(wrb) ((wrb)->wb_nrtx)
|
||||
# define WRB_IOB(wrb) ((wrb)->wb_iob)
|
||||
# define WRB_COPYOUT(wrb,dest,n) (iob_copyout(dest,(wrb)->wb_iob,(n),0))
|
||||
# define WRB_COPYIN(wrb,src,n) (iob_copyin((wrb)->wb_iob,src,(n),0))
|
||||
# define WRB_TRIM(wrb,n) (iob_trimhead((wrb)->wb_iob,(n)))
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
# define WRB_DUMP(msg,wrb) tcp_writebuffer_dump(msg,wrb)
|
||||
#else
|
||||
# define WRB_DUMP(mgs,wrb)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
@@ -170,22 +190,28 @@ struct uip_conn
|
||||
|
||||
/* Read-ahead buffering.
|
||||
*
|
||||
* readahead - A singly linked list of type struct uip_readahead_s
|
||||
* where the TCP/IP read-ahead data is retained.
|
||||
* readahead - A singly linked list of type struct uip_readahead_s
|
||||
* where the TCP/IP read-ahead data is retained.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_TCP_READAHEAD
|
||||
sq_queue_t readahead; /* Read-ahead buffering */
|
||||
#endif
|
||||
|
||||
/* Write buffering */
|
||||
/* Write buffering
|
||||
*
|
||||
* write_q - The queue of unsent I/O buffers. The head of this
|
||||
* list may be partially sent. FIFO ordering.
|
||||
* unacked_q - A queue of completely sent, but unacked I/O buffer
|
||||
* chains. Sequence number ordering.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||
sq_queue_t write_q; /* Write buffering for segments */
|
||||
sq_queue_t unacked_q; /* Write buffering for un-ACKed segments */
|
||||
size_t expired; /* Number segments retransmitted but not yet ACKed,
|
||||
uint16_t expired; /* Number segments retransmitted but not yet ACKed,
|
||||
* it can only be updated at UIP_ESTABLISHED state */
|
||||
size_t sent; /* The number of bytes sent */
|
||||
uint16_t sent; /* The number of bytes sent */
|
||||
uint32_t isn; /* Initial sequence number */
|
||||
#endif
|
||||
|
||||
@@ -261,14 +287,15 @@ struct uip_readahead_s
|
||||
/* This structure supports TCP write buffering */
|
||||
|
||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||
struct iob_s; /* Forward reference */
|
||||
struct tcp_wrbuffer_s
|
||||
{
|
||||
sq_entry_t wb_node; /* Supports a singly linked list */
|
||||
uint32_t wb_seqno; /* Sequence number of the write segment */
|
||||
uint16_t wb_nbytes; /* Number of bytes available in this buffer */
|
||||
uint16_t wb_sent; /* Number of bytes sent from the I/O buffer chain */
|
||||
uint8_t wb_nrtx; /* The number of retransmissions for the last
|
||||
* segment sent */
|
||||
uint8_t wb_buffer[CONFIG_NET_TCP_WRITE_BUFSIZE];
|
||||
struct iob_s *wb_iob; /* Head of the I/O buffer chain */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -391,7 +391,14 @@ extern int uip_lockedwait(sem_t *sem);
|
||||
* len The maximum amount of data bytes to be sent.
|
||||
*/
|
||||
|
||||
extern void uip_send(struct uip_driver_s *dev, const void *buf, int len);
|
||||
extern void uip_send(FAR struct uip_driver_s *dev, FAR const void *buf,
|
||||
int len);
|
||||
|
||||
#ifdef CONFIG_NET_IOB
|
||||
struct iob_s;
|
||||
extern void uip_iobsend(FAR struct uip_driver_s *dev, FAR struct iob_s *buf,
|
||||
unsigned int len, unsigned int offset);
|
||||
#endif
|
||||
|
||||
/* uIP convenience and converting functions.
|
||||
*
|
||||
|
||||
@@ -305,30 +305,6 @@
|
||||
# undef CONFIG_NET_NTCP_READAHEAD_BUFFERS
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
|
||||
/* Number of TCP write buffers */
|
||||
|
||||
# ifndef CONFIG_NET_NTCP_WRITE_BUFFERS
|
||||
# define CONFIG_NET_NTCP_WRITE_BUFFERS 1
|
||||
# endif
|
||||
|
||||
/* The size of one TCP write buffer */
|
||||
|
||||
# ifndef CONFIG_NET_TCP_WRITE_BUFSIZE
|
||||
# define CONFIG_NET_TCP_WRITE_BUFSIZE UIP_TCP_MSS
|
||||
# endif
|
||||
|
||||
/* The size of the write buffer should not exceed the maximum TCP MSS */
|
||||
|
||||
# if CONFIG_NET_TCP_WRITE_BUFSIZE > UIP_TCP_MSS
|
||||
# error CONFIG_NET_TCP_WRITE_BUFSIZE must not exceed UIP_TCP_MSS
|
||||
# endif
|
||||
|
||||
#else
|
||||
# undef CONFIG_NET_TCP_WRITE_BUFSIZE
|
||||
# undef CONFIG_NET_NTCP_WRITE_BUFFERS
|
||||
#endif
|
||||
|
||||
/* Delay after receive to catch a following packet. No delay should be
|
||||
* required if TCP/IP read-ahead buffering is enabled.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user