iperf: handle NO_MEM error in OpenThread iperf

* simplify iperf send/recv loop
pull/7966/head
zhangwenxu 2021-10-25 14:47:05 +08:00 zatwierdzone przez bot
rodzic 9044374032
commit 0fe32adb58
3 zmienionych plików z 30 dodań i 60 usunięć

Wyświetl plik

@ -1,16 +1,8 @@
// Copyright 2021 Espressif Systems (Shanghai) CO LTD /*
// * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// You may obtain a copy of the License at */
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
#include <string.h> #include <string.h>
#include "esp_netif.h" #include "esp_netif.h"
@ -55,10 +47,15 @@ static err_t openthread_output_ip6(struct netif *netif, struct pbuf *p, const st
pbuf_free(q); pbuf_free(q);
} }
/* Check error */ /* Check error */
if (unlikely(ret != ESP_OK)) { switch(ret) {
return ERR_ABRT; case ESP_ERR_NO_MEM:
} else { return ERR_MEM;
case ESP_OK:
return ERR_OK; return ERR_OK;
default:
return ERR_ABRT;
} }
} }

Wyświetl plik

@ -9,6 +9,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/param.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
@ -111,36 +112,25 @@ static esp_err_t iperf_start_report(void)
static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, uint8_t type) static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, uint8_t type)
{ {
bool udp_recv_start = true; bool iperf_recv_start = true;
uint8_t *buffer; uint8_t *buffer;
int want_recv = 0; int want_recv = 0;
int actual_recv = 0; int actual_recv = 0;
socklen_t addr_len = sizeof(struct sockaddr); socklen_t socklen = (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
const char *error_log = (type == IPERF_TRANS_TYPE_TCP) ? "tcp server recv" : "udp server recv";
buffer = s_iperf_ctrl.buffer; buffer = s_iperf_ctrl.buffer;
want_recv = s_iperf_ctrl.buffer_len; want_recv = s_iperf_ctrl.buffer_len;
while (!s_iperf_ctrl.finish) { while (!s_iperf_ctrl.finish) {
if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV6) { actual_recv = recvfrom(recv_socket, buffer, want_recv, 0, (struct sockaddr *)&listen_addr, &socklen);
addr_len = sizeof(struct sockaddr_in6);
actual_recv = recvfrom(recv_socket, buffer, want_recv, 0, (struct sockaddr *)&listen_addr, &addr_len);
} else if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV4) {
addr_len = sizeof(struct sockaddr_in);
actual_recv = recvfrom(recv_socket, buffer, want_recv, 0, (struct sockaddr *)&listen_addr, &addr_len);
}
if (actual_recv < 0) { if (actual_recv < 0) {
if (type == IPERF_TRANS_TYPE_TCP) { iperf_show_socket_error_reason(error_log, recv_socket);
iperf_show_socket_error_reason("tcp server recv", recv_socket);
}
if (type == IPERF_TRANS_TYPE_UDP) {
iperf_show_socket_error_reason("udp server recv", recv_socket);
}
s_iperf_ctrl.finish = true; s_iperf_ctrl.finish = true;
break; break;
} else { } else {
if (udp_recv_start) { if (iperf_recv_start) {
iperf_start_report(); iperf_start_report();
udp_recv_start = false; iperf_recv_start = false;
} }
s_iperf_ctrl.actual_len += actual_recv; s_iperf_ctrl.actual_len += actual_recv;
} }
@ -149,51 +139,35 @@ static void socket_recv(int recv_socket, struct sockaddr_storage listen_addr, ui
static void socket_send(int send_socket, struct sockaddr_storage dest_addr, uint8_t type) static void socket_send(int send_socket, struct sockaddr_storage dest_addr, uint8_t type)
{ {
bool retry = false;
uint8_t *buffer; uint8_t *buffer;
uint8_t delay = 0; uint8_t delay = 1;
int actual_send = 0; int actual_send = 0;
int want_send = 0; int want_send = 0;
int err = 0; int err = 0;
const socklen_t socklen = (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in);
const char *error_log = (type == IPERF_TRANS_TYPE_TCP) ? "tcp client send" : "udp client send";
buffer = s_iperf_ctrl.buffer; buffer = s_iperf_ctrl.buffer;
want_send = s_iperf_ctrl.buffer_len; want_send = s_iperf_ctrl.buffer_len;
iperf_start_report(); iperf_start_report();
while (!s_iperf_ctrl.finish) { while (!s_iperf_ctrl.finish) {
if (type == IPERF_TRANS_TYPE_UDP) { actual_send = sendto(send_socket, buffer, want_send, 0, (struct sockaddr *)&dest_addr, socklen);
if (false == retry) {
delay = 1;
}
retry = false;
}
if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV6) {
actual_send = sendto(send_socket, buffer, want_send, 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr_in6));
} else if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV4) {
actual_send = sendto(send_socket, buffer, want_send, 0, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr_in));
}
if (actual_send != want_send) { if (actual_send != want_send) {
if (type == IPERF_TRANS_TYPE_UDP) { if (type == IPERF_TRANS_TYPE_UDP) {
err = iperf_get_socket_error_code(send_socket); err = iperf_get_socket_error_code(send_socket);
if (err == ENOMEM) { if (err == ENOMEM) {
vTaskDelay(delay); vTaskDelay(delay);
if (delay < IPERF_MAX_DELAY) { delay = MIN(delay << 1, IPERF_MAX_DELAY);
delay <<= 1;
}
retry = true;
continue;
} else { } else {
if (s_iperf_ctrl.cfg.type == IPERF_IP_TYPE_IPV4) { iperf_show_socket_error_reason(error_log, send_socket);
ESP_LOGE(TAG, "udp client send abort: err=%d", err);
}
} }
} } else if (type == IPERF_TRANS_TYPE_TCP) {
if (type == IPERF_TRANS_TYPE_TCP) { iperf_show_socket_error_reason(error_log, send_socket);
iperf_show_socket_error_reason("tcp client send", send_socket);
ESP_LOGI(TAG, "tcp client send error\n");
break; break;
} }
} else { } else {
delay = 1;
s_iperf_ctrl.actual_len += actual_send; s_iperf_ctrl.actual_len += actual_send;
} }
} }

Wyświetl plik

@ -1450,7 +1450,6 @@ components/lwip/port/esp32/include/sntp/sntp_get_set_time.h
components/lwip/port/esp32/include/sys/socket.h components/lwip/port/esp32/include/sys/socket.h
components/lwip/port/esp32/netif/dhcp_state.c components/lwip/port/esp32/netif/dhcp_state.c
components/lwip/port/esp32/netif/ethernetif.c components/lwip/port/esp32/netif/ethernetif.c
components/lwip/port/esp32/netif/openthreadif.c
components/lwip/port/esp32/netif/wlanif.c components/lwip/port/esp32/netif/wlanif.c
components/lwip/port/esp32/no_vfs_syscalls.c components/lwip/port/esp32/no_vfs_syscalls.c
components/lwip/port/esp32/vfs_lwip.c components/lwip/port/esp32/vfs_lwip.c