Fix bug that could cause desynchronization

This commit is contained in:
Keith Winstein
2011-10-10 03:57:29 -04:00
parent 3f2956ee61
commit 56b4064686
+8 -17
View File
@@ -1,3 +1,5 @@
#include <algorithm>
#include "transportsender.hpp" #include "transportsender.hpp"
#include "transportfragment.hpp" #include "transportfragment.hpp"
@@ -135,9 +137,8 @@ void TransportSender<MyState>::add_sent_state( uint64_t the_timestamp, uint64_t
sent_states.push_back( TimestampedState<MyState>( the_timestamp, num, state ) ); sent_states.push_back( TimestampedState<MyState>( the_timestamp, num, state ) );
if ( sent_states.size() > 32 ) { /* limit on state queue */ if ( sent_states.size() > 32 ) { /* limit on state queue */
auto last = sent_states.end(); auto last = sent_states.end();
last--; for ( int i = 0; i < 16; i++ ) { last--; }
last--; sent_states.erase( last ); /* erase state from middle of queue */
sent_states.erase( last ); /* erase penultimate state */
} }
} }
@@ -264,21 +265,11 @@ void TransportSender<MyState>::send_in_fragments( string diff, uint64_t new_num
template <class MyState> template <class MyState>
void TransportSender<MyState>::process_acknowledgment_through( uint64_t ack_num ) void TransportSender<MyState>::process_acknowledgment_through( uint64_t ack_num )
{ {
/* Check if state being acknowledged is one we have culled */ /* Ignore ack if we have culled the state it's acknowledging */
assert( !sent_states.empty() );
if ( sent_states.back().num < ack_num ) { if ( sent_states.end() != find_if( sent_states.begin(), sent_states.end(),
return; [ack_num]( TimestampedState<MyState> x ) { return x.num == ack_num; } ) ) {
} sent_states.remove_if( [ack_num]( TimestampedState<MyState> x ) { return x.num < ack_num; } );
typename list< TimestampedState<MyState> >::iterator i = sent_states.begin();
while ( i != sent_states.end() ) {
typename list< TimestampedState<MyState> >::iterator inext = i;
inext++;
if ( i->num < ack_num ) {
sent_states.erase( i );
}
i = inext;
} }
assert( !sent_states.empty() ); assert( !sent_states.empty() );