summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-22 11:47:47 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-22 11:47:47 +0000
commit63cf8fdb4a79a08572e2488d65a040ba733bdfbc (patch)
tree6f35c361f2e392eccb276dbc8bb365a45cf5fae9 /src/tools
parentf5ca2eed99c8fa741e8d2e8385d1b4f10e433df8 (diff)
parentc50f6c28cb7f97e5a919e696ffb096001a68664a (diff)
downloadouroboros-63cf8fdb4a79a08572e2488d65a040ba733bdfbc.tar.gz
ouroboros-63cf8fdb4a79a08572e2488d65a040ba733bdfbc.zip
Merged in dstaesse/ouroboros/testing (pull request #387)
tools: Fix overflow bug in oping
Diffstat (limited to 'src/tools')
-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");
}