]> arthur.barton.de Git - bup.git/commitdiff
DemuxConn.__init__: you can't assume the *last* 6 bytes are BUPMUX.
authorAvery Pennarun <apenwarr@gmail.com>
Thu, 3 Feb 2011 23:12:52 +0000 (15:12 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Thu, 3 Feb 2011 23:28:34 +0000 (15:28 -0800)
The actual muxed data might arrive immediately after it, and since we're not
buffering that, we have to read one byte at a time.

(Buffering would be more efficient if we expected this to happen frequently,
but it shouldn't.)

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/helpers.py

index 20339a628852293564d124394aa6118bebd583f7..931d43d63ea40405294176368f97b4dc5bf2e0e1 100644 (file)
@@ -328,13 +328,12 @@ class DemuxConn(BaseConn):
         # multiplexed and can be assumed to be debug/log before mux init.
         tail = ''
         while tail != 'BUPMUX':
-            b = os.read(infd, 1024)
+            b = os.read(infd, (len(tail) < 6) and (6-len(tail)) or 1)
             if not b:
                 raise IOError('demux: unexpected EOF during initialization')
             tail += b
-            buf = tail[:-6]
+            sys.stderr.write(tail[:-6])  # pre-mux log messages
             tail = tail[-6:]
-            sys.stderr.write(buf)
         self.infd = infd
         self.reader = None
         self.buf = None
@@ -351,7 +350,7 @@ class DemuxConn(BaseConn):
         assert(rl[0] == self.infd)
         ns = ''.join(checked_reader(self.infd, 5))
         n, fdw = struct.unpack('!IB', ns)
-        assert(n<=MAX_PACKET)
+        assert(n <= MAX_PACKET)
         if fdw == 1:
             self.reader = checked_reader(self.infd, n)
         elif fdw == 2: