Skip to content

Commit

Permalink
Measure the final packet with recv timeout also if idle is zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
bluhm committed Jan 24, 2024
1 parent 77f8dda commit fd91a7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2019-2022 Alexander Bluhm <[email protected]>
Copyright (c) 2019-2024 Alexander Bluhm <[email protected]>
Copyright (c) 2022 Moritz Buhl <[email protected]>

Permission to use, copy, modify, and distribute this software for any
Expand Down
19 changes: 8 additions & 11 deletions udpbench.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 Alexander Bluhm <[email protected]>
* Copyright (c) 2019-2024 Alexander Bluhm <[email protected]>
* Copyright (c) 2022 Moritz Buhl <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
Expand Down Expand Up @@ -764,6 +764,7 @@ udp_receive(int udp_socket, int udp_family)
char *payload;
size_t udplen;
ssize_t rcvlen;
socklen_t len;
int pkts;

udplen = udplength;
Expand Down Expand Up @@ -811,15 +812,11 @@ udp_receive(int udp_socket, int udp_family)

timerclear(&final);
timerclear(&timeo);
if (idle) {
socklen_t len;

timeo.tv_usec = 100000;
len = sizeof(timeo);
if (setsockopt(udp_socket, SOL_SOCKET, SO_RCVTIMEO, &timeo,
len) == -1)
err(1, "setsockopt recv timeout");
}
timeo.tv_usec = 100000;
len = sizeof(timeo);
if (setsockopt(udp_socket, SOL_SOCKET, SO_RCVTIMEO, &timeo, len) == -1)
err(1, "setsockopt recv timeout");

syscall = 1;
packet = 1;
bored = 0;
Expand All @@ -838,7 +835,7 @@ udp_receive(int udp_socket, int udp_family)
/* packet was seen before timeout */
timersub(&final, &timeo, &final);
}
if (bored * timeo.tv_usec >
if (idle && bored * timeo.tv_usec >
1000000L * idle ) {
/* more than a second idle time */
break;
Expand Down

0 comments on commit fd91a7b

Please sign in to comment.