Variable wait time
This commit is contained in:
+10
-7
@@ -49,19 +49,22 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, 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 */
|
||||
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 <class MyState, class RemoteState>
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
+2
-6
@@ -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" );
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user