Skip to content

Commit 48fc6c7

Browse files
committed
throw in max and avg rtt as well
1 parent 1c1a9ba commit 48fc6c7

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

reliable.c

+40-4
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ struct reliable_endpoint_t
509509
double time;
510510
float rtt;
511511
float rtt_min;
512+
float rtt_max;
513+
float rtt_avg;
512514
float jitter;
513515
float packet_loss;
514516
float sent_bandwidth_kbps;
@@ -1343,21 +1345,43 @@ void reliable_endpoint_update( struct reliable_endpoint_t * endpoint, double tim
13431345

13441346
endpoint->time = time;
13451347

1346-
// calculate min rtt
1348+
// calculate min and max rtt
13471349
{
13481350
float min_rtt = 10000.0f;
1351+
float max_rtt = 0.0f;
1352+
float sum_rtt = 0.0f;
1353+
int count = 0;
13491354
for ( int i = 0; i < endpoint->config.rtt_history_size; i++ )
13501355
{
1351-
if ( endpoint->rtt_history_buffer[i] >= 0.0f && endpoint->rtt_history_buffer[i] < min_rtt )
1356+
const float rtt = endpoint->rtt_history_buffer[i];
1357+
if ( rtt >= 0.0f )
13521358
{
1353-
min_rtt = endpoint->rtt_history_buffer[i];
1359+
if ( rtt < min_rtt )
1360+
{
1361+
min_rtt = rtt;
1362+
}
1363+
if ( rtt > max_rtt )
1364+
{
1365+
max_rtt = rtt;
1366+
}
1367+
sum_rtt += rtt;
1368+
count++;
13541369
}
13551370
}
13561371
if ( min_rtt == 10000.0f )
13571372
{
13581373
min_rtt = 0.0f;
13591374
}
13601375
endpoint->rtt_min = min_rtt;
1376+
endpoint->rtt_max = max_rtt;
1377+
if ( count > 0 )
1378+
{
1379+
endpoint->rtt_avg = sum_rtt / (float)count;
1380+
}
1381+
else
1382+
{
1383+
endpoint->rtt_avg = 0.0f;
1384+
}
13611385
}
13621386

13631387
// calculate jitter
@@ -1544,6 +1568,18 @@ float reliable_endpoint_rtt_min( struct reliable_endpoint_t * endpoint )
15441568
return endpoint->rtt_min;
15451569
}
15461570

1571+
float reliable_endpoint_rtt_max( struct reliable_endpoint_t * endpoint )
1572+
{
1573+
reliable_assert( endpoint );
1574+
return endpoint->rtt_max;
1575+
}
1576+
1577+
float reliable_endpoint_rtt_avg( struct reliable_endpoint_t * endpoint )
1578+
{
1579+
reliable_assert( endpoint );
1580+
return endpoint->rtt_avg;
1581+
}
1582+
15471583
float reliable_endpoint_jitter( struct reliable_endpoint_t * endpoint )
15481584
{
15491585
reliable_assert( endpoint );
@@ -2454,7 +2490,7 @@ void test_fragment_cleanup()
24542490

24552491
void reliable_test()
24562492
{
2457-
//while ( 1 )
2493+
// while ( 1 )
24582494
{
24592495
RUN_TEST( test_endian );
24602496
RUN_TEST( test_sequence_buffer );

reliable.h

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ float reliable_endpoint_rtt( struct reliable_endpoint_t * endpoint );
142142

143143
float reliable_endpoint_rtt_min( struct reliable_endpoint_t * endpoint );
144144

145+
float reliable_endpoint_rtt_max( struct reliable_endpoint_t * endpoint );
146+
147+
float reliable_endpoint_rtt_avg( struct reliable_endpoint_t * endpoint );
148+
145149
float reliable_endpoint_jitter( struct reliable_endpoint_t * endpoint );
146150

147151
float reliable_endpoint_packet_loss( struct reliable_endpoint_t * endpoint );

0 commit comments

Comments
 (0)