feat(lwip): Increase send speed of nonblock TCP

This commit is contained in:
dongheng
2019-02-26 16:23:24 +08:00
parent c2712842cf
commit dfcbb6d31e
3 changed files with 51 additions and 7 deletions

View File

@ -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

View File

@ -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

View File

@ -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