@@ -509,6 +509,8 @@ struct reliable_endpoint_t
509
509
double time ;
510
510
float rtt ;
511
511
float rtt_min ;
512
+ float rtt_max ;
513
+ float rtt_avg ;
512
514
float jitter ;
513
515
float packet_loss ;
514
516
float sent_bandwidth_kbps ;
@@ -1343,21 +1345,43 @@ void reliable_endpoint_update( struct reliable_endpoint_t * endpoint, double tim
1343
1345
1344
1346
endpoint -> time = time ;
1345
1347
1346
- // calculate min rtt
1348
+ // calculate min and max rtt
1347
1349
{
1348
1350
float min_rtt = 10000.0f ;
1351
+ float max_rtt = 0.0f ;
1352
+ float sum_rtt = 0.0f ;
1353
+ int count = 0 ;
1349
1354
for ( int i = 0 ; i < endpoint -> config .rtt_history_size ; i ++ )
1350
1355
{
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 )
1352
1358
{
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 ++ ;
1354
1369
}
1355
1370
}
1356
1371
if ( min_rtt == 10000.0f )
1357
1372
{
1358
1373
min_rtt = 0.0f ;
1359
1374
}
1360
1375
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
+ }
1361
1385
}
1362
1386
1363
1387
// calculate jitter
@@ -1544,6 +1568,18 @@ float reliable_endpoint_rtt_min( struct reliable_endpoint_t * endpoint )
1544
1568
return endpoint -> rtt_min ;
1545
1569
}
1546
1570
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
+
1547
1583
float reliable_endpoint_jitter ( struct reliable_endpoint_t * endpoint )
1548
1584
{
1549
1585
reliable_assert ( endpoint );
@@ -2454,7 +2490,7 @@ void test_fragment_cleanup()
2454
2490
2455
2491
void reliable_test ()
2456
2492
{
2457
- //while ( 1 )
2493
+ // while ( 1 )
2458
2494
{
2459
2495
RUN_TEST ( test_endian );
2460
2496
RUN_TEST ( test_sequence_buffer );
0 commit comments