Merge pull request #3639 from tannewt/fix_recv
Rework socketpool.Socket.recv to return sooner
This commit is contained in:
commit
81bb92bdd2
|
@ -79,15 +79,15 @@ mp_uint_t common_hal_socketpool_socket_send(socketpool_socket_obj_t* self, const
|
|||
|
||||
mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self, const uint8_t* buf, mp_uint_t len) {
|
||||
size_t received = 0;
|
||||
ssize_t last_read = 1;
|
||||
int status = 0;
|
||||
uint64_t start_ticks = supervisor_ticks_ms64();
|
||||
int sockfd;
|
||||
esp_err_t err = esp_tls_get_conn_sockfd(self->tcp, &sockfd);
|
||||
if (err != ESP_OK) {
|
||||
mp_raise_OSError(MP_EBADF);
|
||||
}
|
||||
while (received < len &&
|
||||
last_read > 0 &&
|
||||
while (received == 0 &&
|
||||
status >= 0 &&
|
||||
(self->timeout_ms == 0 || supervisor_ticks_ms64() - start_ticks <= self->timeout_ms) &&
|
||||
!mp_hal_is_interrupted()) {
|
||||
RUN_BACKGROUND_TASKS;
|
||||
|
@ -95,27 +95,25 @@ mp_uint_t common_hal_socketpool_socket_recv_into(socketpool_socket_obj_t* self,
|
|||
if (available == 0) {
|
||||
// This reads the raw socket buffer and is used for non-TLS connections
|
||||
// and between encrypted TLS blocks.
|
||||
int status = lwip_ioctl(sockfd, FIONREAD, &available);
|
||||
if (status < 0) {
|
||||
last_read = status;
|
||||
break;
|
||||
}
|
||||
status = lwip_ioctl(sockfd, FIONREAD, &available);
|
||||
}
|
||||
size_t remaining = len - received;
|
||||
if (available > remaining) {
|
||||
available = remaining;
|
||||
}
|
||||
if (available > 0) {
|
||||
last_read = esp_tls_conn_read(self->tcp, (void*) buf + received, available);
|
||||
received += last_read;
|
||||
status = esp_tls_conn_read(self->tcp, (void*) buf + received, available);
|
||||
if (status > 0) {
|
||||
received += status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (last_read == 0) {
|
||||
if (received == 0) {
|
||||
// socket closed
|
||||
common_hal_socketpool_socket_close(self);
|
||||
}
|
||||
if (last_read < 0) {
|
||||
if (status < 0) {
|
||||
mp_raise_BrokenPipeError();
|
||||
}
|
||||
return received;
|
||||
|
|
|
@ -135,6 +135,7 @@ CONFIG_COMPILER_STACK_CHECK_MODE_NONE=y
|
|||
# CONFIG_COMPILER_STACK_CHECK_MODE_ALL is not set
|
||||
# CONFIG_COMPILER_WARN_WRITE_STRINGS is not set
|
||||
# CONFIG_COMPILER_DISABLE_GCC8_WARNINGS is not set
|
||||
# CONFIG_COMPILER_DUMP_RTL_FILES is not set
|
||||
# end of Compiler options
|
||||
|
||||
#
|
||||
|
@ -263,6 +264,11 @@ CONFIG_ESP32S2_ALLOW_RTC_FAST_MEM_AS_HEAP=y
|
|||
# CONFIG_PM_ENABLE is not set
|
||||
# end of Power Management
|
||||
|
||||
#
|
||||
# ADC-Calibration
|
||||
#
|
||||
# end of ADC-Calibration
|
||||
|
||||
#
|
||||
# Common ESP-related
|
||||
#
|
||||
|
@ -332,12 +338,13 @@ CONFIG_ESP_TIMER_IMPL_SYSTIMER=y
|
|||
#
|
||||
# Wi-Fi
|
||||
#
|
||||
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=10
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
|
||||
CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=4
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=8
|
||||
# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
|
||||
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32
|
||||
CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM=16
|
||||
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=16
|
||||
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
|
||||
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
|
||||
CONFIG_ESP32_WIFI_TX_BA_WIN=6
|
||||
|
@ -401,6 +408,7 @@ CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0
|
|||
# CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set
|
||||
CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y
|
||||
# CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set
|
||||
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
|
||||
CONFIG_FREERTOS_DEBUG_OCDAWARE=y
|
||||
# end of FreeRTOS
|
||||
|
||||
|
@ -439,7 +447,7 @@ CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
|
|||
# CONFIG_LWIP_L2_TO_L3_COPY is not set
|
||||
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
|
||||
CONFIG_LWIP_TIMERS_ONDEMAND=y
|
||||
CONFIG_LWIP_MAX_SOCKETS=10
|
||||
CONFIG_LWIP_MAX_SOCKETS=4
|
||||
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
|
||||
# CONFIG_LWIP_SO_LINGER is not set
|
||||
CONFIG_LWIP_SO_REUSE=y
|
||||
|
@ -459,6 +467,9 @@ CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=32
|
|||
CONFIG_LWIP_DHCP_DOES_ARP_CHECK=y
|
||||
# CONFIG_LWIP_DHCP_RESTORE_LAST_IP is not set
|
||||
|
||||
#
|
||||
# CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH is not set
|
||||
|
||||
#
|
||||
# DHCP server
|
||||
#
|
||||
|
@ -474,15 +485,15 @@ CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8
|
|||
#
|
||||
# TCP
|
||||
#
|
||||
CONFIG_LWIP_MAX_ACTIVE_TCP=16
|
||||
CONFIG_LWIP_MAX_LISTENING_TCP=16
|
||||
CONFIG_LWIP_MAX_ACTIVE_TCP=4
|
||||
CONFIG_LWIP_MAX_LISTENING_TCP=4
|
||||
CONFIG_LWIP_TCP_MAXRTX=12
|
||||
CONFIG_LWIP_TCP_SYNMAXRTX=6
|
||||
CONFIG_LWIP_TCP_MSS=1440
|
||||
CONFIG_LWIP_TCP_TMR_INTERVAL=250
|
||||
CONFIG_LWIP_TCP_MSL=60000
|
||||
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
|
||||
CONFIG_LWIP_TCP_WND_DEFAULT=5744
|
||||
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=2880
|
||||
CONFIG_LWIP_TCP_WND_DEFAULT=2880
|
||||
CONFIG_LWIP_TCP_RECVMBOX_SIZE=6
|
||||
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
|
||||
# CONFIG_LWIP_TCP_SACK_OUT is not set
|
||||
|
@ -505,6 +516,8 @@ CONFIG_LWIP_TCPIP_TASK_AFFINITY_NO_AFFINITY=y
|
|||
# CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0 is not set
|
||||
CONFIG_LWIP_TCPIP_TASK_AFFINITY=0x7FFFFFFF
|
||||
# CONFIG_LWIP_PPP_SUPPORT is not set
|
||||
CONFIG_LWIP_IPV6_MEMP_NUM_ND6_QUEUE=3
|
||||
CONFIG_LWIP_IPV6_ND6_NUM_NEIGHBORS=5
|
||||
# CONFIG_LWIP_SLIP_SUPPORT is not set
|
||||
|
||||
#
|
||||
|
@ -552,8 +565,10 @@ CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC=y
|
|||
# CONFIG_MBEDTLS_CUSTOM_MEM_ALLOC is not set
|
||||
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
|
||||
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
|
||||
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096
|
||||
# CONFIG_MBEDTLS_DYNAMIC_BUFFER is not set
|
||||
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=2048
|
||||
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
|
||||
# CONFIG_MBEDTLS_DEBUG is not set
|
||||
|
||||
#
|
||||
|
@ -706,6 +721,7 @@ CONFIG_SPI_FLASH_YIELD_DURING_ERASE=y
|
|||
CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS=20
|
||||
CONFIG_SPI_FLASH_ERASE_YIELD_TICKS=1
|
||||
CONFIG_SPI_FLASH_WRITE_CHUNK_SIZE=8192
|
||||
# CONFIG_SPI_FLASH_SIZE_OVERRIDE is not set
|
||||
|
||||
#
|
||||
# Auto-detect flash chips
|
||||
|
@ -824,8 +840,8 @@ CONFIG_TCP_MAXRTX=12
|
|||
CONFIG_TCP_SYNMAXRTX=6
|
||||
CONFIG_TCP_MSS=1440
|
||||
CONFIG_TCP_MSL=60000
|
||||
CONFIG_TCP_SND_BUF_DEFAULT=5744
|
||||
CONFIG_TCP_WND_DEFAULT=5744
|
||||
CONFIG_TCP_SND_BUF_DEFAULT=2880
|
||||
CONFIG_TCP_WND_DEFAULT=2880
|
||||
CONFIG_TCP_RECVMBOX_SIZE=6
|
||||
CONFIG_TCP_QUEUE_OOSEQ=y
|
||||
# CONFIG_ESP_TCP_KEEP_CONNECTION_WHEN_IP_CHANGES is not set
|
||||
|
|
Loading…
Reference in New Issue