mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-08-06 07:00:05 +08:00
feat(lwip): Increase send speed of nonblock TCP
This commit is contained in:
@ -63,6 +63,12 @@ config LWIP_SOCKET_MULTITHREAD
|
|||||||
Enable the option can enable LWIP socket multithread and all
|
Enable the option can enable LWIP socket multithread and all
|
||||||
function will be thread safe.
|
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
|
config SET_SOLINGER_DEFAULT
|
||||||
bool "set socket SO_LINGER default"
|
bool "set socket SO_LINGER default"
|
||||||
default y
|
default y
|
||||||
|
@ -371,13 +371,31 @@ sent_tcp(void *arg, struct tcp_pcb *pcb, u16_t len)
|
|||||||
lwip_netconn_do_close_internal(conn WRITE_DELAYED);
|
lwip_netconn_do_close_internal(conn WRITE_DELAYED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the queued byte- or pbuf-count drops below the configured low-water limit,
|
#if ESP_NONBLOCK
|
||||||
let select mark this pcb as writable again. */
|
int dontblock = netconn_is_nonblocking(conn)
|
||||||
if ((conn->pcb.tcp != NULL) && (tcp_sndbuf(conn->pcb.tcp) > TCP_SNDLOWAT) &&
|
| (conn->flags & NETCONN_FLAG_CHECK_WRITESPACE);
|
||||||
(tcp_sndqueuelen(conn->pcb.tcp) < TCP_SNDQUEUELOWAT)) {
|
|
||||||
conn->flags &= ~NETCONN_FLAG_CHECK_WRITESPACE;
|
if (dontblock && conn->pcb.tcp) {
|
||||||
API_EVENT(conn, NETCONN_EVT_SENDPLUS, len);
|
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;
|
return ERR_OK;
|
||||||
@ -1560,7 +1578,7 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
|||||||
{
|
{
|
||||||
err_t err;
|
err_t err;
|
||||||
const void *dataptr;
|
const void *dataptr;
|
||||||
u16_t len, available;
|
u16_t len = 0, available;
|
||||||
u8_t write_finished = 0;
|
u8_t write_finished = 0;
|
||||||
size_t diff;
|
size_t diff;
|
||||||
u8_t dontblock;
|
u8_t dontblock;
|
||||||
@ -1608,6 +1626,9 @@ lwip_netconn_do_writemore(struct netconn *conn WRITE_DELAYED_PARAM)
|
|||||||
if (dontblock) {
|
if (dontblock) {
|
||||||
if (!len) {
|
if (!len) {
|
||||||
err = ERR_WOULDBLOCK;
|
err = ERR_WOULDBLOCK;
|
||||||
|
#if ESP_NONBLOCK
|
||||||
|
conn->flags |= NETCONN_FLAG_CHECK_WRITESPACE;
|
||||||
|
#endif /* ESP_NONBLOCK */
|
||||||
goto err_mem;
|
goto err_mem;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1687,6 +1708,17 @@ err_mem:
|
|||||||
conn->write_offset = 0;
|
conn->write_offset = 0;
|
||||||
conn->state = NETCONN_NONE;
|
conn->state = NETCONN_NONE;
|
||||||
NETCONN_SET_SAFE_ERR(conn, err);
|
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 LWIP_TCPIP_CORE_LOCKING
|
||||||
if (delayed)
|
if (delayed)
|
||||||
#endif
|
#endif
|
||||||
|
@ -66,6 +66,12 @@
|
|||||||
#define SOCKETS_MT
|
#define SOCKETS_MT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_ENABLE_NONBLOCK_SPEEDUP
|
||||||
|
#define ESP_NONBLOCK 1
|
||||||
|
#else
|
||||||
|
#define ESP_NONBLOCK 0
|
||||||
|
#endif
|
||||||
|
|
||||||
//#define SOCKETS_TCP_TRACE
|
//#define SOCKETS_TCP_TRACE
|
||||||
|
|
||||||
#define TCP_HIGH_SPEED_RETRANSMISSION CONFIG_TCP_HIGH_SPEED_RETRANSMISSION
|
#define TCP_HIGH_SPEED_RETRANSMISSION CONFIG_TCP_HIGH_SPEED_RETRANSMISSION
|
||||||
|
Reference in New Issue
Block a user