diff --git a/subsys/net/lib/zperf/zperf_session.c b/subsys/net/lib/zperf/zperf_session.c index 3b72367e179..6fff4abf9cc 100644 --- a/subsys/net/lib/zperf/zperf_session.c +++ b/subsys/net/lib/zperf/zperf_session.c @@ -102,14 +102,27 @@ void zperf_reset_session_stats(struct session *session) session->last_transit_time = 0; } -void zperf_session_init(void) +void zperf_session_reset(enum session_proto proto) { int i, j; + if (proto >= SESSION_PROTO_END) { + return; + } + + i = (int)proto; + + for (j = 0; j < SESSION_MAX; j++) { + sessions[i][j].state = STATE_NULL; + zperf_reset_session_stats(&(sessions[i][j])); + } +} + +void zperf_session_init(void) +{ + int i; + for (i = 0; i < SESSION_PROTO_END; i++) { - for (j = 0; j < SESSION_MAX; j++) { - sessions[i][j].state = STATE_NULL; - zperf_reset_session_stats(&(sessions[i][j])); - } + zperf_session_reset(i); } } diff --git a/subsys/net/lib/zperf/zperf_session.h b/subsys/net/lib/zperf/zperf_session.h index ea28dec2c60..f01bc66b71a 100644 --- a/subsys/net/lib/zperf/zperf_session.h +++ b/subsys/net/lib/zperf/zperf_session.h @@ -58,5 +58,7 @@ struct session *get_session(const struct sockaddr *addr, enum session_proto proto); void zperf_session_init(void); void zperf_reset_session_stats(struct session *session); +/* Reset all sessions for a given protocol. */ +void zperf_session_reset(enum session_proto proto); #endif /* __ZPERF_SESSION_H */ diff --git a/subsys/net/lib/zperf/zperf_tcp_receiver.c b/subsys/net/lib/zperf/zperf_tcp_receiver.c index 09624dd07b7..3efd3ff630b 100644 --- a/subsys/net/lib/zperf/zperf_tcp_receiver.c +++ b/subsys/net/lib/zperf/zperf_tcp_receiver.c @@ -117,6 +117,8 @@ static void tcp_receiver_cleanup(void) tcp_server_running = false; tcp_session_cb = NULL; + + zperf_session_reset(SESSION_TCP); } static int tcp_recv_data(struct net_socket_service_event *pev) diff --git a/subsys/net/lib/zperf/zperf_udp_receiver.c b/subsys/net/lib/zperf/zperf_udp_receiver.c index 64f489ed8dc..ae1ac063300 100644 --- a/subsys/net/lib/zperf/zperf_udp_receiver.c +++ b/subsys/net/lib/zperf/zperf_udp_receiver.c @@ -240,6 +240,8 @@ static void udp_receiver_cleanup(void) udp_server_running = false; udp_session_cb = NULL; + + zperf_session_reset(SESSION_UDP); } static int udp_recv_data(struct net_socket_service_event *pev)