[Zodb-checkins] CVS: ZODB3/ZEO/zrpc - smac.py:1.34.2.3

Jeremy Hylton jeremy at zope.com
Fri Jun 6 13:53:47 EDT 2003


Update of /cvs-repository/ZODB3/ZEO/zrpc
In directory cvs.zope.org:/tmp/cvs-serv8147

Modified Files:
      Tag: ZODB3-3_1-branch
	smac.py 
Log Message:
Add some comments to explain the logic.


=== ZODB3/ZEO/zrpc/smac.py 1.34.2.2 => 1.34.2.3 ===
--- ZODB3/ZEO/zrpc/smac.py:1.34.2.2	Tue Nov 12 15:18:09 2002
+++ ZODB3/ZEO/zrpc/smac.py	Fri Jun  6 12:53:47 2003
@@ -99,13 +99,18 @@
             if not d:
                 return
 
+            # Alternate between reading a 4-byte header and a
+            # variable-length payload.  If state is false,
+            # the next message should be the length.
+
             input_len = self.__input_len + len(d)
             msg_size = self.__msg_size
             state = self.__state
 
-            inp = self.__inp
             if msg_size > input_len:
-                if inp is None:
+                # If there isn't enough data to have a complete
+                # message, add the new data to buffer and return.
+                if self.__inp is None:
                     self.__inp = d
                 elif type(self.__inp) is StringType:
                     self.__inp = [self.__inp, d]
@@ -114,19 +119,22 @@
                 self.__input_len = input_len
                 return # keep waiting for more input
 
+            inp = self.__inp
             # load all previous input and d into single string inp
             if isinstance(inp, StringType):
-                inp = inp + d
+                inp += d
             elif inp is None:
                 inp = d
             else:
                 inp.append(d)
                 inp = "".join(inp)
 
+            # Consume as many messages as possible from the
+            # current input buffer.
             offset = 0
             while (offset + msg_size) <= input_len:
                 msg = inp[offset:offset + msg_size]
-                offset = offset + msg_size
+                offset += msg_size
                 if not state:
                     # waiting for message
                     msg_size = struct.unpack(">i", msg)[0]




More information about the Zodb-checkins mailing list