sin.sin_port = htons(port);
sin.sin_addr = destinations[dst_num];
- fprintf(stderr, "connecting %u\n", i);
-
if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
perror("connect()");
exit(1);
}
- fprintf(stderr, "connected\n");
-
while (num_bytes > 0) {
unsigned bytes_to_send = num_bytes;
unsigned ret;
char buf[65536];
unsigned long long bytes_received = 0;
- fprintf(stderr, "Receiver started\n");
-
for ( ;; ) {
int ret = read(sock, buf, 65536);
if (ret == 0)
break;
+ bytes_received += ret;
+
// update the central counter after every 1MB (8ms
// at gigabit speeds, should be enough) of received data
if (bytes_received > 1048576) {
pthread_mutex_lock(&receive_mutex);
- total_bytes_sent += bytes_received;
+ total_bytes_received += bytes_received;
pthread_mutex_unlock(&receive_mutex);
bytes_received = 0;
}
}
- sleep(3600);
+ // Just stay around collecting statistics until we're done.
+ for ( ;; ) {
+ unsigned long long sent, received;
+ static unsigned long long last_sent = 0, last_received = 0;
+ double recv_rate, send_rate;
+
+ pthread_mutex_lock(&send_mutex);
+ sent = total_bytes_sent;
+ pthread_mutex_unlock(&send_mutex);
+
+ pthread_mutex_lock(&receive_mutex);
+ received = total_bytes_received;
+ pthread_mutex_unlock(&receive_mutex);
+
+ send_rate = (sent - last_sent) * 8.0 / 1048576.0;
+ recv_rate = (received - last_received) * 8.0 / 1048576.0;
+
+ printf("%12llu %12llu %5.0f Mbit/sec %5.0f Mbit/sec\n", sent, received,
+ send_rate, recv_rate);
+
+ last_sent = sent;
+ last_received = received;
+
+ sleep(1);
+ }
exit(0);
}