task #7040 (Work on tcp_enqueue): Don't waste memory when chaining segments, added option TCP_OVERSIZE to prevent creating many small pbufs when calling tcp_write with many small blocks of data. Instead, pbufs are allocated larger than needed and the space is used for later calls to tcp_write.
This commit is contained in:
@@ -937,6 +937,24 @@
|
||||
#define TCP_DEFAULT_LISTEN_BACKLOG 0xff
|
||||
#endif
|
||||
|
||||
/**
|
||||
* TCP_OVERSIZE: The maximum number of bytes that tcp_write may
|
||||
* allocate ahead of time in an attempt to create shorter pbuf chains
|
||||
* for transmission. The meaningful range is 0 to TCP_MSS. Some
|
||||
* suggested values are:
|
||||
*
|
||||
* 0: Disable oversized allocation. Each tcp_write() allocates a new
|
||||
pbuf (old behaviour).
|
||||
* 1: Allocate size-aligned pbufs with minimal excess. Use this if your
|
||||
* scatter-gather DMA requires aligned fragments.
|
||||
* 128: Limit the pbuf/memory overhead to 20%.
|
||||
* TCP_MSS: Try to create unfragmented TCP packets.
|
||||
* TCP_MSS/4: Try to create 4 fragments or less per TCP packet.
|
||||
*/
|
||||
#ifndef TCP_OVERSIZE
|
||||
#define TCP_OVERSIZE TCP_MSS
|
||||
#endif
|
||||
|
||||
/**
|
||||
* LWIP_TCP_TIMESTAMPS==1: support the TCP timestamp option.
|
||||
*/
|
||||
|
||||
@@ -230,8 +230,12 @@ struct tcp_pcb {
|
||||
u16_t snd_buf; /* Available buffer space for sending (in bytes). */
|
||||
#define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
|
||||
u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */
|
||||
|
||||
|
||||
|
||||
#if TCP_OVERSIZE
|
||||
/* Extra bytes available at the end of the last pbuf in unsent. */
|
||||
u16_t unsent_oversize;
|
||||
#endif /* TCP_OVERSIZE */
|
||||
|
||||
/* These are ordered by sequence number: */
|
||||
struct tcp_seg *unsent; /* Unsent (queued) segments. */
|
||||
struct tcp_seg *unacked; /* Sent but unacknowledged segments. */
|
||||
@@ -342,7 +346,7 @@ void tcp_abort (struct tcp_pcb *pcb);
|
||||
err_t tcp_close (struct tcp_pcb *pcb);
|
||||
err_t tcp_shutdown(struct tcp_pcb *pcb, int shut_rx, int shut_tx);
|
||||
|
||||
/* Flags for "apiflags" parameter in tcp_write and tcp_enqueue */
|
||||
/* Flags for "apiflags" parameter in tcp_write */
|
||||
#define TCP_WRITE_FLAG_COPY 0x01
|
||||
#define TCP_WRITE_FLAG_MORE 0x02
|
||||
|
||||
|
||||
@@ -177,6 +177,8 @@ PACK_STRUCT_END
|
||||
#define TCPH_OFFSET_SET(phdr, offset) (phdr)->_hdrlen_rsvd_flags = htons(((offset) << 8) | TCPH_FLAGS(phdr))
|
||||
#define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | TCPH_FLAGS(phdr))
|
||||
#define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & htons((u16_t)(~(u16_t)(TCP_FLAGS)))) | htons(flags))
|
||||
#define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = htons(((len) << 12) | (flags))
|
||||
|
||||
#define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | htons(flags))
|
||||
#define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = htons(ntohs((phdr)->_hdrlen_rsvd_flags) | (TCPH_FLAGS(phdr) & ~(flags)) )
|
||||
|
||||
@@ -384,9 +386,8 @@ struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);
|
||||
(pcb)->flags |= TF_ACK_NOW; \
|
||||
} while (0)
|
||||
|
||||
err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);
|
||||
err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,
|
||||
u8_t flags, u8_t apiflags, u8_t optflags);
|
||||
err_t tcp_send_fin(struct tcp_pcb *pcb);
|
||||
err_t tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags);
|
||||
|
||||
void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user