Skip to content

Commit

Permalink
Merge branch 'bugfix/fix_iperf_exit_error_v3.2' into 'release/v3.2'
Browse files Browse the repository at this point in the history
examples: fix iperf exit error

See merge request idf/esp-idf!4842
  • Loading branch information
jack0c committed Apr 28, 2019
2 parents df874cd + d9cdbcd commit a08c77a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions examples/wifi/iperf/components/iperf/iperf.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void iperf_report_task(void *arg)
(double)((s_iperf_ctrl.total_len - last_len) * 8) / interval / 1e6);
cur += interval;
last_len = s_iperf_ctrl.total_len;
if (cur == time) {
if (cur >= time) {
break;
}
}
Expand Down Expand Up @@ -160,7 +160,6 @@ static esp_err_t IRAM_ATTR iperf_run_tcp_server(void)
return ESP_FAIL;
}

iperf_start_report();
buffer = s_iperf_ctrl.buffer;
want_recv = s_iperf_ctrl.buffer_len;
while (!s_iperf_ctrl.finish) {
Expand All @@ -173,6 +172,7 @@ static esp_err_t IRAM_ATTR iperf_run_tcp_server(void)
return ESP_FAIL;
} else {
printf("accept: %s,%d\n", inet_ntoa(remote_addr.sin_addr), htons(remote_addr.sin_port));
iperf_start_report();

t.tv_sec = IPERF_SOCKET_RX_TIMEOUT;
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(t));
Expand All @@ -182,6 +182,7 @@ static esp_err_t IRAM_ATTR iperf_run_tcp_server(void)
actual_recv = recv(sockfd, buffer, want_recv, 0);
if (actual_recv < 0) {
iperf_show_socket_error_reason("tcp server recv", listen_socket);
s_iperf_ctrl.finish = true;
break;
} else {
s_iperf_ctrl.total_len += actual_recv;
Expand All @@ -206,6 +207,7 @@ static esp_err_t IRAM_ATTR iperf_run_udp_server(void)
uint8_t *buffer;
int sockfd;
int opt;
bool udp_recv_start = true ;

sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sockfd < 0) {
Expand All @@ -227,7 +229,6 @@ static esp_err_t IRAM_ATTR iperf_run_udp_server(void)
addr.sin_port = htons(s_iperf_ctrl.cfg.sport);
addr.sin_addr.s_addr = s_iperf_ctrl.cfg.sip;

iperf_start_report();
buffer = s_iperf_ctrl.buffer;
want_recv = s_iperf_ctrl.buffer_len;
ESP_LOGI(TAG, "want recv=%d", want_recv);
Expand All @@ -240,6 +241,10 @@ static esp_err_t IRAM_ATTR iperf_run_udp_server(void)
if (actual_recv < 0) {
iperf_show_socket_error_reason("udp server recv", sockfd);
} else {
if(udp_recv_start){
iperf_start_report();
udp_recv_start = false;
}
s_iperf_ctrl.total_len += actual_recv;
}
}
Expand Down Expand Up @@ -350,6 +355,7 @@ static esp_err_t iperf_run_tcp_client(void)
}
}

s_iperf_ctrl.finish = true;
close(sockfd);
return ESP_OK;
}
Expand Down

0 comments on commit a08c77a

Please sign in to comment.