From 0dfd7b80241421104f844efa7abf6111d9facb24 Mon Sep 17 00:00:00 2001 From: ehofman Date: Mon, 29 Jun 2009 14:23:26 +0000 Subject: [PATCH] If more than one packet has arrived in the mean time, process them all. --- src/Network/generic.cxx | 47 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index e2651d06e..74a7090a0 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -446,32 +446,41 @@ bool FGGeneric::process() { goto error_out; } } else if ( get_direction() == SG_IO_IN ) { - if (!binary_mode) { - if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) { - parse_message(); + if ( io->get_type() == sgFileType ) { + if (!binary_mode) { + length = io->readline( buf, FG_MAX_MSG_SIZE ); + if ( length > 0 ) { + parse_message(); + } else { + SG_LOG( SG_IO, SG_ALERT, "Error reading data." ); + return false; + } } else { - SG_LOG( SG_IO, SG_ALERT, "Error reading data." ); - return false; - } - } else { - if ( (length = io->read( buf, binary_record_length )) > 0 ) { - if (length != binary_record_length) { + length = io->read( buf, binary_record_length ); + if ( length == binary_record_length ) { + parse_message(); + } else { SG_LOG( SG_IO, SG_ALERT, "Generic protocol: Received binary " "record of unexpected size, expected: " - << binary_record_length << "received: " + << binary_record_length << " but received: " << length); - } else { - SG_LOG( SG_IO, SG_DEBUG, - "Generic protocol: received record of " << length << - " bytes."); - parse_message(); } - } else { - SG_LOG( SG_IO, SG_INFO, - "Generic protocol: Error reading data." ); - return false; } + } else { + do { + if (!binary_mode) { + length = io->readline( buf, FG_MAX_MSG_SIZE ); + if ( length > 0 ) { + parse_message(); + } + } else { + length = io->read( buf, binary_record_length ); + if ( length == binary_record_length ) { + parse_message(); + } + } + } while ( length == binary_record_length ); } } return true;