Dynamic send interval

This commit is contained in:
Keith Winstein
2011-08-16 23:41:16 -04:00
parent 7e37221d36
commit cf5f4bc558
2 changed files with 22 additions and 6 deletions
+19 -5
View File
@@ -37,12 +37,25 @@ Transport<MyState, RemoteState>::Transport( MyState &initial_state, RemoteState
/* client */
}
template <class MyState, class RemoteState>
unsigned int Transport<MyState, RemoteState>::send_interval( void )
{
unsigned int SEND_INTERVAL = connection.timeout() / 2;
if ( SEND_INTERVAL < SEND_INTERVAL_MIN ) {
SEND_INTERVAL = SEND_INTERVAL_MIN;
} else if ( SEND_INTERVAL > SEND_INTERVAL_MAX ) {
SEND_INTERVAL = SEND_INTERVAL_MAX;
}
return SEND_INTERVAL;
}
/* Returns the number of ms to wait until next (possible) event */
template <class MyState, class RemoteState>
int Transport<MyState, RemoteState>::tick( void )
{
/* 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 >= send_interval() ) {
/* Update assumed receiver state */
update_assumed_receiver_state();
@@ -52,10 +65,10 @@ int Transport<MyState, RemoteState>::tick( void )
/* Send diffs or ack */
send_to_receiver();
return SEND_INTERVAL;
return send_interval();
}
int64_t wait = sent_states.back().timestamp + SEND_INTERVAL - timestamp();
int64_t wait = sent_states.back().timestamp + send_interval() - timestamp();
if ( wait < 0 ) {
wait = 0;
}
@@ -305,9 +318,10 @@ void Transport<MyState, RemoteState>::send_in_fragments( string diff, uint64_t n
connection.send( s, send_timestamp );
if ( verbose ) {
fprintf( stderr, "Sent [%d=>%d] frag %d, ack=%d, throwaway=%d, len=%d\n",
fprintf( stderr, "Sent [%d=>%d] frag %d, ack=%d, throwaway=%d, len=%d, frame rate=%.2f\n",
(int)inst.old_num, (int)inst.new_num, (int)inst.fragment_num,
(int)inst.ack_num, (int)inst.throwaway_num, (int)inst.diff.size() );
(int)inst.ack_num, (int)inst.throwaway_num, (int)inst.diff.size(),
1000.0 / (double)send_interval() );
}
} while ( !diff.empty() );
}
+3 -1
View File
@@ -76,11 +76,13 @@ namespace Network {
class Transport
{
private:
static const int SEND_INTERVAL = 50; /* ms between frames */
static const unsigned int SEND_INTERVAL_MIN = 20; /* ms between frames */
static const unsigned int SEND_INTERVAL_MAX = 250; /* ms between frames */
static const int ACK_INTERVAL = 1000; /* ms between empty acks */
static const int HEADER_LEN = 120;
/* helper methods for tick() */
unsigned int send_interval( void );
void update_assumed_receiver_state( void );
void rationalize_states( void );
void send_to_receiver( void );