Skip to content

Commit e8c9775

Browse files
committed
[nrf fromlist] net: zperf: Fix TCP packet counting
Make sure we send the entire packet buffer before bumping the packet counter, send() does not guarantee that all of the requested data will be sent at once with STREAM socket. Upstream PR: zephyrproject-rtos/zephyr#65251 Signed-off-by: Robert Lubos <[email protected]>
1 parent 67fddd3 commit e8c9775

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

subsys/net/lib/zperf/zperf_tcp_uploader.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@ static char sample_packet[PACKET_SIZE_MAX];
2020

2121
static struct zperf_async_upload_context tcp_async_upload_ctx;
2222

23+
static ssize_t sendall(int sock, const void *buf, size_t len)
24+
{
25+
while (len) {
26+
ssize_t out_len = zsock_send(sock, buf, len, 0);
27+
28+
if (out_len < 0) {
29+
return out_len;
30+
}
31+
32+
buf = (const char *)buf + out_len;
33+
len -= out_len;
34+
}
35+
36+
return 0;
37+
}
38+
2339
static int tcp_upload(int sock,
2440
unsigned int duration_in_ms,
2541
unsigned int packet_size,
@@ -50,7 +66,7 @@ static int tcp_upload(int sock,
5066

5167
do {
5268
/* Send the packet */
53-
ret = zsock_send(sock, sample_packet, packet_size, 0);
69+
ret = sendall(sock, sample_packet, packet_size);
5470
if (ret < 0) {
5571
if (nb_errors == 0 && ret != -ENOMEM) {
5672
NET_ERR("Failed to send the packet (%d)", errno);

0 commit comments

Comments
 (0)