]> git.mxchange.org Git - flightgear.git/commitdiff
reorganize the code a bit to prevent an infinite loop in ascii mode
authorehofman <ehofman>
Sun, 7 Feb 2010 12:40:42 +0000 (12:40 +0000)
committerTim Moore <timoore33@gmail.com>
Wed, 10 Feb 2010 14:02:42 +0000 (15:02 +0100)
src/Network/generic.cxx

index a91f7835eba45a8a2d56d5427b6d20eebfa509ee..487ff67aec7575dbdf3c06135805f4163b5f1358 100644 (file)
@@ -467,25 +467,24 @@ bool FGGeneric::process() {
                 }
             }
         } 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();
-                    } else if ( length > 0 ) {
-                        SG_LOG( SG_IO, SG_ALERT,
-                            "Generic protocol: Received binary "
-                            "record of unexpected size, expected: "
-                            << binary_record_length << " but received: "
-                            << length);
-                    }
+            if (!binary_mode) {
+                while ((length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
+                    parse_message();
                 }
-            } while ( length == binary_record_length );
+            } else {
+                while ((length = io->read( buf, binary_record_length )) 
+                          == binary_record_length ) {
+                    parse_message();
+                }
+
+                if ( length > 0 ) {
+                    SG_LOG( SG_IO, SG_ALERT,
+                        "Generic protocol: Received binary "
+                        "record of unexpected size, expected: "
+                        << binary_record_length << " but received: "
+                        << length);
+                }
+            }
         }
     }
     return true;