Fix timing of echo acks

This commit is contained in:
Keith Winstein
2012-02-26 02:49:53 -05:00
parent afacda98e4
commit e5c8c33f4f
5 changed files with 49 additions and 9 deletions
+25 -1
View File
@@ -106,8 +106,9 @@ bool Complete::operator==( Complete const &x ) const
return (terminal == x.terminal) && (echo_ack == x.echo_ack);
}
void Complete::set_echo_ack( uint64_t now )
bool Complete::set_echo_ack( uint64_t now )
{
bool ret = false;
uint64_t newest_echo_ack = 0;
for ( BOOST_AUTO( i, input_history.begin() ); i != input_history.end(); i++ ) {
@@ -118,10 +119,33 @@ void Complete::set_echo_ack( uint64_t now )
input_history.remove_if( (&_1)->*&pair<uint64_t, uint64_t>::first < newest_echo_ack );
if ( echo_ack != newest_echo_ack ) {
ret = true;
}
echo_ack = newest_echo_ack;
return ret;
}
void Complete::register_input_frame( uint64_t n, uint64_t now )
{
input_history.push_back( make_pair( n, now ) );
}
int Complete::wait_time( uint64_t now ) const
{
if ( input_history.size() < 2 ) {
return INT_MAX;
}
BOOST_AUTO( it, input_history.begin() );
it++;
uint64_t next_echo_ack_time = it->second + ECHO_TIMEOUT;
if ( next_echo_ack_time <= now ) {
return 0;
} else {
return next_echo_ack_time - now;
}
}
+2 -1
View File
@@ -49,8 +49,9 @@ namespace Terminal {
bool parser_grounded( void ) const { return parser.is_grounded(); }
uint64_t get_echo_ack( void ) const { return echo_ack; }
void set_echo_ack( uint64_t now );
bool set_echo_ack( uint64_t now );
void register_input_frame( uint64_t n, uint64_t now );
int wait_time( uint64_t now ) const;
/* interface for Network::Transport */
void subtract( const Complete * ) {}
+2 -1
View File
@@ -68,7 +68,8 @@ namespace Network {
void push_back( Parser::UserByte s_userbyte ) { actions.push_back( UserEvent( s_userbyte ) ); }
void push_back( Parser::Resize s_resize ) { actions.push_back( UserEvent( s_resize ) ); }
size_t size( void ) { return actions.size(); }
bool empty( void ) const { return actions.empty(); }
size_t size( void ) const { return actions.size(); }
const Parser::Action *get_action( unsigned int i );
/* interface for Network::Transport */