Explicit echo ack protobuf with reliable semantics

This commit is contained in:
Keith Winstein
2012-02-25 14:34:39 -05:00
parent e9ce05bc7b
commit 3a92cd1393
13 changed files with 72 additions and 51 deletions
+36 -2
View File
@@ -16,6 +16,9 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <boost/typeof/typeof.hpp>
#include <boost/lambda/lambda.hpp>
#include "completeterminal.h"
#include "hostinput.pb.h"
@@ -24,6 +27,7 @@ using namespace std;
using namespace Parser;
using namespace Terminal;
using namespace HostBuffers;
using namespace boost::lambda;
string Complete::act( const string &str )
{
@@ -52,10 +56,16 @@ string Complete::act( const Action *act )
}
/* interface for Network::Transport */
string Complete::diff_from( const Complete &existing )
string Complete::diff_from( const Complete &existing ) const
{
HostBuffers::HostMessage output;
if ( existing.get_echo_ack() != get_echo_ack() ) {
assert( get_echo_ack() >= existing.get_echo_ack() );
Instruction *new_echo = output.add_instruction();
new_echo->MutableExtension( echoack )->set_echo_ack_num( get_echo_ack() );
}
if ( !(existing.get_fb() == get_fb()) ) {
if ( (existing.get_fb().ds.get_width() != terminal.get_fb().ds.get_width())
|| (existing.get_fb().ds.get_height() != terminal.get_fb().ds.get_height()) ) {
@@ -82,6 +92,10 @@ void Complete::apply_string( string diff )
} else if ( input.instruction( i ).HasExtension( resize ) ) {
act( new Resize( input.instruction( i ).GetExtension( resize ).width(),
input.instruction( i ).GetExtension( resize ).height() ) );
} else if ( input.instruction( i ).HasExtension( echoack ) ) {
uint64_t inst_echo_ack_num = input.instruction( i ).GetExtension( echoack ).echo_ack_num();
assert( inst_echo_ack_num >= echo_ack );
echo_ack = inst_echo_ack_num;
}
}
}
@@ -89,5 +103,25 @@ void Complete::apply_string( string diff )
bool Complete::operator==( Complete const &x ) const
{
// assert( parser == x.parser ); /* parser state is irrelevant for us */
return terminal == x.terminal;
return (terminal == x.terminal) && (echo_ack == x.echo_ack);
}
void Complete::set_echo_ack( uint64_t now )
{
uint64_t newest_echo_ack = 0;
for ( BOOST_AUTO( i, input_history.begin() ); i != input_history.end(); i++ ) {
if ( i->second < now - ECHO_TIMEOUT ) {
newest_echo_ack = i->first;
}
}
input_history.remove_if( (&_1)->*&pair<uint64_t, uint64_t>::first < newest_echo_ack );
echo_ack = newest_echo_ack;
}
void Complete::register_input_frame( uint64_t n, uint64_t now )
{
input_history.push_back( make_pair( n, now ) );
}
+15 -2
View File
@@ -19,6 +19,9 @@
#ifndef COMPLETE_TERMINAL_HPP
#define COMPLETE_TERMINAL_HPP
#include <list>
#include <stdint.h>
#include "parser.h"
#include "terminal.h"
@@ -30,8 +33,14 @@ namespace Terminal {
Parser::UTF8Parser parser;
Terminal::Emulator terminal;
std::list< std::pair<uint64_t, uint64_t> > input_history;
uint64_t echo_ack;
static const int ECHO_TIMEOUT = 50; /* for late ack */
public:
Complete( size_t width, size_t height ) : parser(), terminal( width, height ) {}
Complete( size_t width, size_t height ) : parser(), terminal( width, height ),
input_history(), echo_ack( 0 ) {}
std::string act( const std::string &str );
std::string act( const Parser::Action *act );
@@ -39,9 +48,13 @@ namespace Terminal {
const Framebuffer & get_fb( void ) const { return terminal.get_fb(); }
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 );
void register_input_frame( uint64_t n, uint64_t now );
/* interface for Network::Transport */
void subtract( const Complete * ) {}
std::string diff_from( const Complete &existing );
std::string diff_from( const Complete &existing ) const;
void apply_string( std::string diff );
bool operator==( const Complete &x ) const;
};
+2 -2
View File
@@ -37,9 +37,9 @@ void UserStream::subtract( const UserStream *prefix )
}
}
string UserStream::diff_from( const UserStream &existing )
string UserStream::diff_from( const UserStream &existing ) const
{
deque<UserEvent>::iterator my_it = actions.begin();
deque<UserEvent>::const_iterator my_it = actions.begin();
for ( deque<UserEvent>::const_iterator i = existing.actions.begin();
i != existing.actions.end();
+1 -1
View File
@@ -73,7 +73,7 @@ namespace Network {
/* interface for Network::Transport */
void subtract( const UserStream *prefix );
string diff_from( const UserStream &existing );
string diff_from( const UserStream &existing ) const;
void apply_string( string diff );
bool operator==( const UserStream &x ) const { return actions == x.actions; }
};