From e7df295f457c473ae76ae4d266f17176a5b31a28 Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Wed, 10 Aug 2011 00:13:22 -0400 Subject: [PATCH] Variable wait time --- networktransport.cpp | 17 ++++++++++------- networktransport.hpp | 2 +- ntester.cpp | 8 ++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/networktransport.cpp b/networktransport.cpp index 4c2779b..d639dd5 100644 --- a/networktransport.cpp +++ b/networktransport.cpp @@ -49,19 +49,22 @@ Transport::Transport( MyState &initial_state, RemoteState } template -void Transport::tick( void ) +int Transport::tick( void ) { - /* Update assumed receiver state */ - update_assumed_receiver_state(); - - /* Cut out common prefix of all states */ - rationalize_states(); - /* Determine if a new diff or empty ack needs to be sent */ if ( timestamp() - sent_states.back().timestamp >= int64_t( SEND_INTERVAL ) ) { + /* Update assumed receiver state */ + update_assumed_receiver_state(); + + /* Cut out common prefix of all states */ + rationalize_states(); + /* Send diffs or ack */ send_to_receiver(); } + + int64_t wait = int64_t( sent_states.back().timestamp + SEND_INTERVAL ) - timestamp(); + return wait; } template diff --git a/networktransport.hpp b/networktransport.hpp index 0a32d0f..464999e 100644 --- a/networktransport.hpp +++ b/networktransport.hpp @@ -87,7 +87,7 @@ namespace Network { Transport( MyState &initial_state, RemoteState &initial_remote, const char *key_str, const char *ip, int port ); - void tick( void ); + int tick( void ); void recv( void ); diff --git a/ntester.cpp b/ntester.cpp index 6294ea9..63555e2 100644 --- a/ntester.cpp +++ b/ntester.cpp @@ -43,9 +43,7 @@ int main( int argc, char *argv[] ) uint64_t last_num = n->get_remote_state_num(); while ( true ) { try { - n->tick(); - - if ( poll( &my_pollfd, 1, 5 ) < 0 ) { + if ( poll( &my_pollfd, 1, n->tick() ) < 0 ) { perror( "poll" ); exit( 1 ); } @@ -94,9 +92,7 @@ int main( int argc, char *argv[] ) while( true ) { try { - n->tick(); - - if ( poll( fds, 2, 5 ) < 0 ) { + if ( poll( fds, 2, n->tick() ) < 0 ) { perror( "poll" ); }