summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-02-22 12:05:57 +0100
committerdimitri staessens <[email protected]>2017-02-22 12:29:27 +0100
commitc50f6c28cb7f97e5a919e696ffb096001a68664a (patch)
tree6f35c361f2e392eccb276dbc8bb365a45cf5fae9
parentf5ca2eed99c8fa741e8d2e8385d1b4f10e433df8 (diff)
downloadouroboros-c50f6c28cb7f97e5a919e696ffb096001a68664a.tar.gz
ouroboros-c50f6c28cb7f97e5a919e696ffb096001a68664a.zip
tools: Fix overflow bug in oping
Sometimes the receiver thread got the SDU before the writer thread has set the sent time when testing over the local. The sent time is now written before actually sending to avoid this.
-rw-r--r--src/tools/oping/oping_client.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c
index ee2d9df6..99c11a68 100644
--- a/src/tools/oping/oping_client.c
+++ b/src/tools/oping/oping_client.c
@@ -86,7 +86,7 @@ void * reader(void * o)
++client.rcvd;
- clock_gettime(CLOCK_REALTIME, &now);
+ clock_gettime(CLOCK_MONOTONIC, &now);
pthread_mutex_lock(&client.lock);
ms = ts_diff_us(&client.times[ntohl(msg->id)], &now)
@@ -105,7 +105,7 @@ void * reader(void * o)
client.rtt_max = ms;
d = (ms - client.rtt_avg);
- client.rtt_avg += d / (float) client.rcvd;
+ client.rtt_avg += d / client.rcvd;
client.rtt_m2 += d * (ms - client.rtt_avg);
}
@@ -140,18 +140,19 @@ void * writer(void * o)
nanosleep(&wait, NULL);
msg->type = htonl(ECHO_REQUEST);
msg->id = htonl(client.sent);
+
+ clock_gettime(CLOCK_MONOTONIC, &now);
+
+ pthread_mutex_lock(&client.lock);
+ client.times[client.sent++] = now;
+ pthread_mutex_unlock(&client.lock);
+
if (flow_write(*fdp, buf, client.size) == -1) {
printf("Failed to send SDU.\n");
flow_dealloc(*fdp);
free(buf);
return (void *) -1;
}
-
- clock_gettime(CLOCK_REALTIME, &now);
-
- pthread_mutex_lock(&client.lock);
- client.times[client.sent++] = now;
- pthread_mutex_unlock(&client.lock);
}
pthread_cleanup_pop(true);
@@ -252,7 +253,7 @@ int client_main(void)
client.rtt_max);
if (client.rcvd > 1)
printf("%.3f ms\n",
- sqrt(client.rtt_m2 / (float) (client.rcvd - 1)));
+ sqrt(client.rtt_m2 / (client.rcvd - 1)));
else
printf("NaN ms\n");
}