Variable wait time

This commit is contained in:
Keith Winstein
2011-08-10 00:13:22 -04:00
parent 4a90f6a0ef
commit e7df295f45
3 changed files with 13 additions and 14 deletions
+10 -7
View File
@@ -49,19 +49,22 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState
} }
template <class MyState, class RemoteState> template <class MyState, class RemoteState>
void Transport<MyState, RemoteState>::tick( void ) int Transport<MyState, RemoteState>::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 */ /* Determine if a new diff or empty ack needs to be sent */
if ( timestamp() - sent_states.back().timestamp >= int64_t( SEND_INTERVAL ) ) { 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 diffs or ack */
send_to_receiver(); send_to_receiver();
} }
int64_t wait = int64_t( sent_states.back().timestamp + SEND_INTERVAL ) - timestamp();
return wait;
} }
template <class MyState, class RemoteState> template <class MyState, class RemoteState>
+1 -1
View File
@@ -87,7 +87,7 @@ namespace Network {
Transport( MyState &initial_state, RemoteState &initial_remote, Transport( MyState &initial_state, RemoteState &initial_remote,
const char *key_str, const char *ip, int port ); const char *key_str, const char *ip, int port );
void tick( void ); int tick( void );
void recv( void ); void recv( void );
+2 -6
View File
@@ -43,9 +43,7 @@ int main( int argc, char *argv[] )
uint64_t last_num = n->get_remote_state_num(); uint64_t last_num = n->get_remote_state_num();
while ( true ) { while ( true ) {
try { try {
n->tick(); if ( poll( &my_pollfd, 1, n->tick() ) < 0 ) {
if ( poll( &my_pollfd, 1, 5 ) < 0 ) {
perror( "poll" ); perror( "poll" );
exit( 1 ); exit( 1 );
} }
@@ -94,9 +92,7 @@ int main( int argc, char *argv[] )
while( true ) { while( true ) {
try { try {
n->tick(); if ( poll( fds, 2, n->tick() ) < 0 ) {
if ( poll( fds, 2, 5 ) < 0 ) {
perror( "poll" ); perror( "poll" );
} }