From 7b1ff634d01c6caefee606897d48e333feb56c6b Mon Sep 17 00:00:00 2001 From: Keith Winstein Date: Fri, 12 Aug 2011 04:51:43 -0400 Subject: [PATCH] Fix getchar() bug --- networktransport.cpp | 8 +++++++- ntester.cpp | 3 ++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/networktransport.cpp b/networktransport.cpp index c3ae5dc..3d7402b 100644 --- a/networktransport.cpp +++ b/networktransport.cpp @@ -75,7 +75,6 @@ void Transport::send_to_receiver( void ) return; } - Instruction inst( assumed_receiver_state->num, assumed_receiver_state->num, received_states.back().num, @@ -94,8 +93,10 @@ void Transport::send_to_receiver( void ) uint64_t new_num; if ( current_state == sent_states.back().state ) { /* previously sent */ new_num = sent_states.back().num; + fprintf( stderr, "Sending OLD state %d\r\n", (int)new_num ); } else { /* new state */ new_num = sent_states.back().num + 1; + fprintf( stderr, "Sending NEW state %d\r\n", (int)new_num ); } bool done = false; @@ -112,6 +113,7 @@ void Transport::send_to_receiver( void ) send_in_fragments( diff, new_num ); done = true; } catch ( MTUException m ) { + fprintf( stderr, "Caught Path MTU exception, MTU now = %d\n", connection.get_MTU() ); done = false; } } @@ -299,6 +301,10 @@ void Transport::send_in_fragments( string diff, uint64_t n fragment_num++, this_fragment ); string s = inst.tostring(); + + fprintf( stderr, "Sending [%d=>%d], len=%u\n", + (int)inst.old_num, (int)inst.new_num, (unsigned int)inst.diff.size() ); + connection.send( s ); } } diff --git a/ntester.cpp b/ntester.cpp index 4ad751b..718e2e5 100644 --- a/ntester.cpp +++ b/ntester.cpp @@ -92,7 +92,8 @@ int main( int argc, char *argv[] ) } if ( fds[ 0 ].revents & POLLIN ) { - char x = getchar(); + char x; + assert( read( STDIN_FILENO, &x, 1 ) == 1 ); n->get_current_state().key_hit( x ); }