diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 420b78ed..af62dc5f 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -63,6 +63,12 @@ config LWIP_SOCKET_MULTITHREAD Enable the option can enable LWIP socket multithread and all function will be thread safe. +config ENABLE_NONBLOCK_SPEEDUP + bool "Speed up send speed of nonblock TCP" + default n + help + Enable this option, send speed of nonblock TCP will increase obviously. + config SET_SOLINGER_DEFAULT bool "set socket SO_LINGER default" default y diff --git a/components/lwip/lwip/src/api/api_msg.c b/components/lwip/lwip/src/api/api_msg.c index 6a0c539b..a5996969 100644 --- a/components/lwip/lwip/src/api/api_msg.c +++ b/components/lwip/lwip/src/api/api_msg.c @@ -371,13 +371,31 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len) lwip_netconn_do_close_internal(conn WRITE_DELAYED); } - /* 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)) { - conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE; - API_EVENT(conn, NETCONN_EVT_SENDPLUS, len); +#if ESP_NONBLOCK + int dontblock = netconn_is_nonblocking(conn) + | (conn->flags & NETCONN_FLAG_CHECK_WRITESPACE); + + if (dontblock && conn->pcb.tcp) { + if (tcp_sndbuf(conn->pcb.tcp) != TCP_SND_BUF) { + tcp_output(conn->pcb.tcp); + } + if ((tcp_sndbuf(conn->pcb.tcp) > 0) && + (tcp_sndqueuelen(conn->pcb.tcp) < TCP_SND_QUEUELEN)) { + conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE; + API_EVENT(conn, NETCONN_EVT_SENDPLUS, len); + } + } else { +#endif /* ESP_NONBLOCK */ + /* 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)) { + conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE; + API_EVENT(conn, NETCONN_EVT_SENDPLUS, len); + } +#if ESP_NONBLOCK } +#endif /* ESP_NONBLOCK */ } return ERR_OK; @@ -1560,7 +1578,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM) { err_t err; const void *dataptr; - u16_t len, available; + u16_t len = 0, available; u8_t write_finished = 0; size_t diff; u8_t dontblock; @@ -1608,6 +1626,9 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM) if (dontblock) { if (!len) { err = ERR_WOULDBLOCK; +#if ESP_NONBLOCK + conn->flags |= NETCONN_FLAG_CHECK_WRITESPACE; +#endif /* ESP_NONBLOCK */ goto err_mem; } } else { @@ -1687,6 +1708,17 @@ err_mem: conn->write_offset = 0; conn->state = NETCONN_NONE; NETCONN_SET_SAFE_ERR(conn, err); + +#if ESP_NONBLOCK + if (dontblock) { + if (tcp_sndbuf(conn->pcb.tcp) > 0 && + (tcp_sndqueuelen(conn->pcb.tcp) < TCP_SND_QUEUELEN)) { + conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE; + API_EVENT(conn, NETCONN_EVT_SENDPLUS, len); + } + } +#endif /* ESP_NONBLOCK */ + #if LWIP_TCPIP_CORE_LOCKING if (delayed) #endif diff --git a/components/lwip/port/esp8266/include/lwipopts.h b/components/lwip/port/esp8266/include/lwipopts.h index fcc07147..82581753 100644 --- a/components/lwip/port/esp8266/include/lwipopts.h +++ b/components/lwip/port/esp8266/include/lwipopts.h @@ -66,6 +66,12 @@ #define SOCKETS_MT #endif +#if CONFIG_ENABLE_NONBLOCK_SPEEDUP +#define ESP_NONBLOCK 1 +#else +#define ESP_NONBLOCK 0 +#endif + //#define SOCKETS_TCP_TRACE #define TCP_HIGH_SPEED_RETRANSMISSION CONFIG_TCP_HIGH_SPEED_RETRANSMISSION