// 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;
received = total_bytes_received;
pthread_mutex_unlock(&receive_mutex);
- printf("%llu %llu\n", sent, received);
+ 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);
}