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.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
This commit is contained in:
Robert Lubos 2023-11-15 17:49:00 +01:00 committed by Fabio Baltieri
parent e6d90b409b
commit aa6f698d31

View file

@ -20,6 +20,22 @@ static char sample_packet[PACKET_SIZE_MAX];
static struct zperf_async_upload_context tcp_async_upload_ctx;
static ssize_t sendall(int sock, const void *buf, size_t len)
{
while (len) {
ssize_t out_len = zsock_send(sock, buf, len, 0);
if (out_len < 0) {
return out_len;
}
buf = (const char *)buf + out_len;
len -= out_len;
}
return 0;
}
static int tcp_upload(int sock,
unsigned int duration_in_ms,
unsigned int packet_size,
@ -50,7 +66,7 @@ static int tcp_upload(int sock,
do {
/* Send the packet */
ret = zsock_send(sock, sample_packet, packet_size, 0);
ret = sendall(sock, sample_packet, packet_size);
if (ret < 0) {
if (nb_errors == 0 && ret != -ENOMEM) {
NET_ERR("Failed to send the packet (%d)", errno);