]> granicus.if.org Git - esp-idf/commitdiff
components/lwip - add per socket tcp window
authorliuzhifu <liuzhifu@espressif.com>
Sat, 22 Oct 2016 16:49:41 +0000 (00:49 +0800)
committerliuzhifu <liuzhifu@espressif.com>
Sat, 22 Oct 2016 16:49:41 +0000 (00:49 +0800)
Add code to support per socket tcp window and tcp send buffer size configuration.

12 files changed:
components/lwip/api/api_msg.c
components/lwip/api/lwip_debug.c
components/lwip/api/sockets.c
components/lwip/core/init.c
components/lwip/core/tcp.c
components/lwip/core/tcp_in.c
components/lwip/core/tcp_out.c
components/lwip/include/lwip/lwip/opt.h
components/lwip/include/lwip/lwip/priv/tcp_priv.h
components/lwip/include/lwip/lwip/sockets.h
components/lwip/include/lwip/lwip/tcp.h
components/lwip/include/lwip/port/lwipopts.h

index e8e967ef4012b7fdbc094a9f1c7ba8d3c70a67dd..9cac2e0e90d41e9ce055cff6b5b73ab90acecdfc 100755 (executable)
@@ -314,8 +314,8 @@ poll_tcp(void *arg, struct tcp_pcb *pcb)
   if (conn->flags & NETCONN_FLAG_CHECK_WRITESPACE) {
     /* If the queued byte- or pbuf-count drops below the configured low-water limit,
        let select mark this pcb as writable again. */
-    if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT) &&
-      (tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
+    if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT(conn->pcb.tcp)) &&
+      (tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT(conn->pcb.tcp))) {
       conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE;
       API_EVENT(conn, NETCONN_EVT_SENDPLUS, 0);
     }
@@ -348,8 +348,8 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
 
     /* If the queued byte- or pbuf-count drops below the configured low-water limit,
        let select mark this pcb as writable again. */
-    if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT) &&
-      (tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
+    if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT(conn->pcb.tcp) &&
+      (tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT(conn->pcb.tcp)))) {
       conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE;
       API_EVENT(conn, NETCONN_EVT_SENDPLUS, len);
     }
@@ -1540,8 +1540,8 @@ err_mem:
            and let poll_tcp check writable space to mark the pcb writable again */
         API_EVENT(conn, NETCONN_EVT_SENDMINUS, len);
         conn->flags |= NETCONN_FLAG_CHECK_WRITESPACE;
-      } else if ((tcp_sndbuf(conn->pcb.tcp) <= TCP_SNDLOWAT) ||
-                 (tcp_sndqueuelen(conn->pcb.tcp) >= TCP_SNDQUEUELOWAT)) {
+      } else if ((tcp_sndbuf(conn->pcb.tcp) <= TCP_SNDLOWAT(conn->pcb.tcp)) ||
+                 (tcp_sndqueuelen(conn->pcb.tcp) >= TCP_SNDQUEUELOWAT(conn->pcb.tcp))) {
         /* The queued byte- or pbuf-count exceeds the configured low-water limit,
            let select mark this pcb as non-writable. */
         API_EVENT(conn, NETCONN_EVT_SENDMINUS, len);
index 1e5fed40d3291677d4db99302fe8170984df7a1d..d73a23e1a3a9ded4d44da4f49b9149a7aa071ad3 100644 (file)
@@ -48,6 +48,9 @@ static void dbg_lwip_tcp_pcb_one_show(struct tcp_pcb* pcb)
     printf("rttest=%d rtseq=%d sa=%d sv=%d\n", pcb->rttest, pcb->rtseq, pcb->sa, pcb->sv);
     printf("rto=%d nrtx=%d\n", pcb->rto, pcb->nrtx);
     printf("dupacks=%d lastack=%d\n", pcb->dupacks, pcb->lastack);
+#if ESP_PER_SOC_TCP_WND
+    printf("per_soc_window=%d per_soc_snd_buf=%d\n", pcb->per_soc_tcp_wnd, pcb->per_soc_tcp_snd_buf);
+#endif
     printf("cwnd=%d ssthreash=%d\n", pcb->cwnd, pcb->ssthresh);
     printf("snd_next=%d snd_wl1=%d snd_wl2=%d\n", pcb->snd_nxt, pcb->snd_wl1, pcb->snd_wl2);
     printf("snd_lbb=%d snd_wnd=%d snd_wnd_max=%d\n", pcb->snd_lbb, pcb->snd_wnd, pcb->snd_wnd_max);
index 350847b57c4f44a63037ae1a68930f66e0a866dd..15226be203af70f16ae6c326d97919312f1b5309 100755 (executable)
@@ -2395,6 +2395,16 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt
                   s, *(int *)optval));
       break;
 #endif /* LWIP_TCP_KEEPALIVE */
+
+#if ESP_PER_SOC_TCP_WND
+    case TCP_WINDOW:
+    *(int*)optval = (int)sock->conn->pcb.tcp->per_soc_tcp_wnd;
+    break;
+    case TCP_SNDBUF:
+    *(int*)optval = (int)sock->conn->pcb.tcp->per_soc_tcp_snd_buf;
+    break;
+#endif
+
     default:
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
                   s, optname));
@@ -2792,6 +2802,16 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
                   s, sock->conn->pcb.tcp->keep_cnt));
       break;
 #endif /* LWIP_TCP_KEEPALIVE */
+
+#if ESP_PER_SOC_TCP_WND
+    case TCP_WINDOW:
+    sock->conn->pcb.tcp->per_soc_tcp_wnd = ((u32_t)(*(const int*)optval)) * TCP_MSS;
+    break;
+    case TCP_SNDBUF:
+    sock->conn->pcb.tcp->per_soc_tcp_snd_buf = ((u32_t)(*(const int*)optval)) * TCP_MSS;
+    break;
+#endif
+
     default:
       LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n",
                   s, optname));
index 2a410d0e46e6ac9251ce8ea2dc4f5531d80437b7..f974aedaf808e9f55d776c19b3fd41a8f71a3028 100755 (executable)
 //#endif
 #else /* LWIP_WND_SCALE */
 
-#ifndef LWIP_ESP8266
+#if (ESP_PER_SOC_TCP_WND == 0)
 #if (LWIP_TCP && (TCP_WND > 0xffff))
   #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)"
 #endif
 #endif
 
 #endif /* LWIP_WND_SCALE */
+
+#if (ESP_PER_SOC_TCP_WND == 0)
 #if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
   #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
 #endif
   #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
 #endif
 
-#ifndef LWIP_ESP8266
 #if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
   #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
 #endif
 #if !MEMP_MEM_MALLOC && (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
   #error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
 #endif
+
+#if (ESP_PER_SOC_TCP_WND == 0)
 #if TCP_SND_BUF < (2 * TCP_MSS)
   #error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
 #endif
 #if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN
   #error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
 #endif
+#endif
+
 #if !MEMP_MEM_MALLOC && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
   #error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
 #endif
 void
 lwip_init(void)
 {
-#ifdef LWIP_ESP8266
-//  MEMP_NUM_TCP_PCB = 5;
-//  TCP_WND = (4 * TCP_MSS);
-//  TCP_MAXRTX = 12;
-//  TCP_SYNMAXRTX = 6;
-#endif
-
   /* Modules initialization */
   stats_init();
 #if !NO_SYS
index e8fda52c8d63a141b341a54016f00b22526d374e..e7ea5610310869b7773bdb4c40349e5a48f5d217 100755 (executable)
@@ -638,7 +638,7 @@ u32_t tcp_update_rcv_ann_wnd(struct tcp_pcb *pcb)
 {
   u32_t new_right_edge = pcb->rcv_nxt + pcb->rcv_wnd;
 
-  if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND / 2), pcb->mss))) {
+  if (TCP_SEQ_GEQ(new_right_edge, pcb->rcv_ann_right_edge + LWIP_MIN((TCP_WND(pcb) / 2), pcb->mss))) {
     /* we can advertise more window */
     pcb->rcv_ann_wnd = pcb->rcv_wnd;
     return new_right_edge - pcb->rcv_ann_right_edge;
@@ -694,10 +694,10 @@ tcp_recved(struct tcp_pcb *pcb, u16_t len)
   wnd_inflation = tcp_update_rcv_ann_wnd(pcb);
 
   /* If the change in the right edge of window is significant (default
-   * watermark is TCP_WND/4), then send an explicit update now.
+   * watermark is TCP_WND(pcb)/4), then send an explicit update now.
    * Otherwise wait for a packet to be sent in the normal course of
    * events (or more window to be available later) */
-  if (wnd_inflation >= TCP_WND_UPDATE_THRESHOLD) {
+  if (wnd_inflation >= TCP_WND_UPDATE_THRESHOLD(pcb)) {
     tcp_ack_now(pcb);
     tcp_output(pcb);
   }
@@ -827,9 +827,9 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
   pcb->snd_lbb = iss - 1;
   /* Start with a window that does not need scaling. When window scaling is
      enabled and used, the window is enlarged when both sides agree on scaling. */
-  pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
+  pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND(pcb));
   pcb->rcv_ann_right_edge = pcb->rcv_nxt;
-  pcb->snd_wnd = TCP_WND;
+  pcb->snd_wnd = TCP_WND(pcb);
   /* As initial send MSS, we use TCP_MSS but limit it to 536.
      The send MSS is updated when an MSS option is received. */
   pcb->mss = (TCP_MSS > 536) ? 536 : TCP_MSS;
@@ -837,7 +837,7 @@ tcp_connect(struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port,
   pcb->mss = tcp_eff_send_mss(pcb->mss, &pcb->local_ip, &pcb->remote_ip);
 #endif /* TCP_CALCULATE_EFF_SEND_MSS */
   pcb->cwnd = 1;
-  pcb->ssthresh = TCP_WND;
+  pcb->ssthresh = TCP_WND(pcb);
 #if LWIP_CALLBACK_API
   pcb->connected = connected;
 #else /* LWIP_CALLBACK_API */
@@ -1581,11 +1581,11 @@ tcp_alloc(u8_t prio)
   if (pcb != NULL) {
     memset(pcb, 0, sizeof(struct tcp_pcb));
     pcb->prio = prio;
-    pcb->snd_buf = TCP_SND_BUF;
+    pcb->snd_buf = TCP_SND_BUF_DEFAULT;
     pcb->snd_queuelen = 0;
     /* Start with a window that does not need scaling. When window scaling is
        enabled and used, the window is enlarged when both sides agree on scaling. */
-    pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND);
+    pcb->rcv_wnd = pcb->rcv_ann_wnd = TCPWND_MIN16(TCP_WND(pcb));
 #if LWIP_WND_SCALE
     /* snd_scale and rcv_scale are zero unless both sides agree to use scaling */
     pcb->snd_scale = 0;
@@ -1608,7 +1608,6 @@ tcp_alloc(u8_t prio)
     pcb->snd_lbb = iss;
     pcb->tmr = tcp_ticks;
     pcb->last_timer = tcp_timer_ctr;
-
     pcb->polltmr = 0;
 
 #if LWIP_CALLBACK_API
@@ -1624,7 +1623,13 @@ tcp_alloc(u8_t prio)
 #endif /* LWIP_TCP_KEEPALIVE */
 
     pcb->keep_cnt_sent = 0;
+
+#if ESP_PER_SOC_TCP_WND
+    pcb->per_soc_tcp_wnd = TCP_WND_DEFAULT;
+    pcb->per_soc_tcp_snd_buf = TCP_SND_BUF_DEFAULT;
+#endif
   }
+
   return pcb;
 }
 
index 25d7403851302c2ccb5ba0346ad4e1ffdd1b048b..90ebf17232eccb91066b4e2933e8355de14a18bd 100755 (executable)
@@ -1745,9 +1745,9 @@ tcp_parseopt(struct tcp_pcb *pcb)
           pcb->rcv_scale = TCP_RCV_SCALE;
           pcb->flags |= TF_WND_SCALE;
           /* window scaling is enabled, we can use the full receive window */
-          LWIP_ASSERT("window not at default value", pcb->rcv_wnd == TCPWND_MIN16(TCP_WND));
-          LWIP_ASSERT("window not at default value", pcb->rcv_ann_wnd == TCPWND_MIN16(TCP_WND));
-          pcb->rcv_wnd = pcb->rcv_ann_wnd = TCP_WND;
+          LWIP_ASSERT("window not at default value", pcb->rcv_wnd == TCPWND_MIN16(TCP_WND(pcb)));
+          LWIP_ASSERT("window not at default value", pcb->rcv_ann_wnd == TCPWND_MIN16(TCP_WND(pcb)));
+          pcb->rcv_wnd = pcb->rcv_ann_wnd = TCP_WND(pcb);
         }
         break;
 #endif
index aac02e4ebe0f269ff4a4a57c1493ca3245cdea1c..5f10befae8fc986a196b9d63ccccc55ad7771a5f 100755 (executable)
@@ -336,9 +336,9 @@ tcp_write_checks(struct tcp_pcb *pcb, u16_t len)
   /* If total number of pbufs on the unsent/unacked queues exceeds the
    * configured maximum, return an error */
   /* check for configured max queuelen and possible overflow */
-  if ((pcb->snd_queuelen >= TCP_SND_QUEUELEN) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
+  if ((pcb->snd_queuelen >= TCP_SND_QUEUELEN(pcb)) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
     LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("tcp_write: too long queue %"U16_F" (max %"U16_F")\n",
-      pcb->snd_queuelen, TCP_SND_QUEUELEN));
+      pcb->snd_queuelen, TCP_SND_QUEUELEN(pcb)));
     TCP_STATS_INC(tcp.memerr);
     pcb->flags |= TF_NAGLEMEMERR;
     return ERR_MEM;
@@ -606,9 +606,9 @@ tcp_write(struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags)
     /* Now that there are more segments queued, we check again if the
      * length of the queue exceeds the configured maximum or
      * overflows. */
-    if ((queuelen > TCP_SND_QUEUELEN) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
+    if ((queuelen > TCP_SND_QUEUELEN(pcb)) || (queuelen > TCP_SNDQUEUELEN_OVERFLOW)) {
       LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("tcp_write: queue too long %"U16_F" (%d)\n",
-        queuelen, (int)TCP_SND_QUEUELEN));
+        queuelen, (int)TCP_SND_QUEUELEN(pcb)));
       pbuf_free(p);
       goto memerr;
     }
@@ -766,10 +766,10 @@ tcp_enqueue_flags(struct tcp_pcb *pcb, u8_t flags)
               (flags & (TCP_SYN | TCP_FIN)) != 0);
 
   /* check for configured max queuelen and possible overflow (FIN flag should always come through!) */
-  if (((pcb->snd_queuelen >= TCP_SND_QUEUELEN) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) &&
+  if (((pcb->snd_queuelen >= TCP_SND_QUEUELEN(pcb)) || (pcb->snd_queuelen > TCP_SNDQUEUELEN_OVERFLOW)) &&
       ((flags & TCP_FIN) == 0)) {
     LWIP_DEBUGF(TCP_OUTPUT_DEBUG | LWIP_DBG_LEVEL_SEVERE, ("tcp_enqueue_flags: too long queue %"U16_F" (max %"U16_F")\n",
-                                       pcb->snd_queuelen, TCP_SND_QUEUELEN));
+                                       pcb->snd_queuelen, TCP_SND_QUEUELEN(pcb)));
     TCP_STATS_INC(tcp.memerr);
     pcb->flags |= TF_NAGLEMEMERR;
     return ERR_MEM;
@@ -1301,6 +1301,7 @@ tcp_rst(u32_t seqno, u32_t ackno,
   struct pbuf *p;
   struct tcp_hdr *tcphdr;
   struct netif *netif;
+  
   p = pbuf_alloc(PBUF_IP, TCP_HLEN, PBUF_RAM);
   if (p == NULL) {
     LWIP_DEBUGF(TCP_DEBUG, ("tcp_rst: could not allocate memory for pbuf\n"));
@@ -1315,10 +1316,18 @@ tcp_rst(u32_t seqno, u32_t ackno,
   tcphdr->seqno = htonl(seqno);
   tcphdr->ackno = htonl(ackno);
   TCPH_HDRLEN_FLAGS_SET(tcphdr, TCP_HLEN/4, TCP_RST | TCP_ACK);
+#if ESP_PER_SOC_TCP_WND
+#if LWIP_WND_SCALE
+  tcphdr->wnd = PP_HTONS(((TCP_WND_DEFAULT >> TCP_RCV_SCALE) & 0xFFFF));
+#else
+  tcphdr->wnd = PP_HTONS(TCP_WND_DEFAULT);
+#endif
+#else
 #if LWIP_WND_SCALE
   tcphdr->wnd = PP_HTONS(((TCP_WND >> TCP_RCV_SCALE) & 0xFFFF));
 #else
   tcphdr->wnd = PP_HTONS(TCP_WND);
+#endif
 #endif
   tcphdr->chksum = 0;
   tcphdr->urgp = 0;
index 76fff88052e66a471ee05763996f0898a0bc1aae..c286712e0d550febe6528c0b671f885925648d8f 100755 (executable)
  * (2 * TCP_MSS) for things to work well
  */
 #ifndef TCP_WND
-#define TCP_WND                         (4 * TCP_MSS)
+#define TCP_WND(pcb)                         (4 * TCP_MSS)
 #endif
 
 /**
  * To achieve good performance, this should be at least 2 * TCP_MSS.
  */
 #ifndef TCP_SND_BUF
-#define TCP_SND_BUF                     (2 * TCP_MSS)
+#define TCP_SND_BUF(pcb)                     (2 * TCP_MSS)
 #endif
 
 /**
  * as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work.
  */
 #ifndef TCP_SND_QUEUELEN
-#define TCP_SND_QUEUELEN                ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS))
+#define TCP_SND_QUEUELEN(pcb)                ((4 * (TCP_SND_BUF((pcb))) + (TCP_MSS - 1))/(TCP_MSS))
 #endif
 
 /**
  * TCP snd_buf for select to return writable (combined with TCP_SNDQUEUELOWAT).
  */
 #ifndef TCP_SNDLOWAT
-#define TCP_SNDLOWAT                    LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1)
+#define TCP_SNDLOWAT(pcb)                    LWIP_MIN(LWIP_MAX(((TCP_SND_BUF((pcb)))/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF((pcb))) - 1)
 #endif
 
 /**
  * this number, select returns writable (combined with TCP_SNDLOWAT).
  */
 #ifndef TCP_SNDQUEUELOWAT
-#define TCP_SNDQUEUELOWAT               LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5)
+#define TCP_SNDQUEUELOWAT(pcb)               LWIP_MAX(((TCP_SND_QUEUELEN((pcb)))/2), 5)
 #endif
 
 /**
  * explicit window update
  */
 #ifndef TCP_WND_UPDATE_THRESHOLD
-#define TCP_WND_UPDATE_THRESHOLD   LWIP_MIN((TCP_WND / 4), (TCP_MSS * 4))
+#define TCP_WND_UPDATE_THRESHOLD(pcb)   LWIP_MIN((TCP_WND((pcb)) / 4), (TCP_MSS * 4))
 #endif
 
 /**
index b5261b445cbde750bac4834488591e0c791a0f29..0c498944b3ef6cd32b3beb4e1860c9f00b006b56 100755 (executable)
@@ -92,7 +92,7 @@ err_t            tcp_process_refused_data(struct tcp_pcb *pcb);
                             ((tpcb)->flags & (TF_NODELAY | TF_INFR)) || \
                             (((tpcb)->unsent != NULL) && (((tpcb)->unsent->next != NULL) || \
                               ((tpcb)->unsent->len >= (tpcb)->mss))) || \
-                            ((tcp_sndbuf(tpcb) == 0) || (tcp_sndqueuelen(tpcb) >= TCP_SND_QUEUELEN)) \
+                            ((tcp_sndbuf(tpcb) == 0) || (tcp_sndqueuelen(tpcb) >= TCP_SND_QUEUELEN(tpcb))) \
                             ) ? 1 : 0)
 #define tcp_output_nagle(tpcb) (tcp_do_output_nagle(tpcb) ? tcp_output(tpcb) : ERR_OK)
 
index aafb3d5cf3e2de2847b0a90005c104639d08654c..fc2b7e2d1227f48a94f416ea5af6ce5cb36363cd 100755 (executable)
@@ -190,7 +190,6 @@ struct msghdr {
 #define SO_CONTIMEO    0x1009 /* Unimplemented: connect timeout */
 #define SO_NO_CHECK    0x100a /* don't create UDP checksum */
 
-
 /*
  * Structure used for manipulating linger option.
  */
@@ -250,6 +249,11 @@ struct linger {
 #define TCP_KEEPIDLE   0x03    /* set pcb->keep_idle  - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
 #define TCP_KEEPINTVL  0x04    /* set pcb->keep_intvl - Use seconds for get/setsockopt */
 #define TCP_KEEPCNT    0x05    /* set pcb->keep_cnt   - Use number of probes sent for get/setsockopt */
+#if ESP_PER_SOC_TCP_WND
+#define TCP_WINDOW     0x06    /* set pcb->per_soc_tcp_wnd */
+#define TCP_SNDBUF     0x07    /* set pcb->per_soc_tcp_snd_buf */
+#endif
+
 #endif /* LWIP_TCP */
 
 #if LWIP_IPV6
index d52040f99c2a5655d768cf000d4247402c84ffa9..6b8c4b6c48d5ea548c76f7fcb67e235cfb0cc90a 100755 (executable)
@@ -129,14 +129,14 @@ typedef err_t (*tcp_connected_fn)(void *arg, struct tcp_pcb *tpcb, err_t err);
 #define RCV_WND_SCALE(pcb, wnd) (((wnd) >> (pcb)->rcv_scale))
 #define SND_WND_SCALE(pcb, wnd) (((wnd) << (pcb)->snd_scale))
 #define TCPWND16(x)             ((u16_t)LWIP_MIN((x), 0xFFFF))
-#define TCP_WND_MAX(pcb)        ((tcpwnd_size_t)(((pcb)->flags & TF_WND_SCALE) ? TCP_WND : TCPWND16(TCP_WND)))
+#define TCP_WND_MAX(pcb)        ((tcpwnd_size_t)(((pcb)->flags & TF_WND_SCALE) ? TCP_WND(pcb) : TCPWND16(TCP_WND(pcb))))
 typedef u32_t tcpwnd_size_t;
 typedef u16_t tcpflags_t;
 #else
 #define RCV_WND_SCALE(pcb, wnd) (wnd)
 #define SND_WND_SCALE(pcb, wnd) (wnd)
 #define TCPWND16(x)             (x)
-#define TCP_WND_MAX(pcb)        TCP_WND
+#define TCP_WND_MAX(pcb)        TCP_WND(pcb)
 typedef u16_t tcpwnd_size_t;
 typedef u8_t tcpflags_t;
 #endif
@@ -236,6 +236,11 @@ struct tcp_pcb {
   u8_t dupacks;
   u32_t lastack; /* Highest acknowledged seqno. */
 
+#if ESP_PER_SOC_TCP_WND
+  tcpwnd_size_t per_soc_tcp_wnd; /* per tcp socket tcp window size */
+  tcpwnd_size_t per_soc_tcp_snd_buf; /* per tcp socket tcp send buffer size */
+#endif
+
   /* congestion avoidance/control variables */
   tcpwnd_size_t cwnd;
   tcpwnd_size_t ssthresh;
@@ -402,6 +407,10 @@ const char* tcp_debug_state_str(enum tcp_state s);
 /* for compatibility with older implementation */
 #define tcp_new_ip6() tcp_new_ip_type(IPADDR_TYPE_V6)
 
+#if ESP_PER_SOC_TCP_WND
+#define PER_SOC_WND(pcb) (pcb->per_soc_wnd)
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 2c24b2be92e082eac22a5ceb8efe56ca85b7219d..5667e2d20bdcae37fbcb137103bc18ccd08140ce 100755 (executable)
@@ -225,18 +225,21 @@ extern unsigned long os_random(void);
  * TCP_WND: The size of a TCP window.  This must be at least
  * (2 * TCP_MSS) for things to work well
  */
-#define PERF 1
+
+#define ESP_PER_SOC_TCP_WND             1
+#if ESP_PER_SOC_TCP_WND
+#define TCP_WND_DEFAULT                      (4*TCP_MSS)
+#define TCP_SND_BUF_DEFAULT                  (2*TCP_MSS)
+
+#define TCP_WND(pcb)                         (pcb->per_soc_tcp_wnd)
+#define TCP_SND_BUF(pcb)                     (pcb->per_soc_tcp_snd_buf)
+#else
 #ifdef PERF
 extern unsigned char misc_prof_get_tcpw(void);
 extern unsigned char misc_prof_get_tcp_snd_buf(void);
-#define TCP_WND                         (misc_prof_get_tcpw()*TCP_MSS)
-#define TCP_SND_BUF                     (misc_prof_get_tcp_snd_buf()*TCP_MSS)
-
-#else
-
-#define TCP_WND                         (4 * TCP_MSS)
-#define TCP_SND_BUF                     (2 * TCP_MSS)
-
+#define TCP_WND(pcb)                         (misc_prof_get_tcpw()*TCP_MSS)
+#define TCP_SND_BUF(pcb)                     (misc_prof_get_tcp_snd_buf()*TCP_MSS)
+#endif
 #endif