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

Jeremy Hylton jeremy@zope.com
Thu, 29 Aug 2002 18:39:51 -0400


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

Modified Files:
	smac.py 
Log Message:
Break long messages into pieces in message_output().

As suggested by Toby Dickenson.


=== ZODB3/ZEO/smac.py 1.21 => 1.22 ===
--- ZODB3/ZEO/smac.py:1.21	Thu Aug 29 12:31:17 2002
+++ ZODB3/ZEO/smac.py	Thu Aug 29 18:39:51 2002
@@ -41,6 +41,10 @@
 expected_socket_write_errors = tuple(tmp_dict.keys())
 del tmp_dict
 
+# We chose 60000 as the socket limit by looking at the largest strings
+# that we could pass to send() without blocking.
+SEND_SIZE = 60000
+
 class SizedMessageAsyncConnection(asyncore.dispatcher):
     __super_init = asyncore.dispatcher.__init__
     __super_close = asyncore.dispatcher.close
@@ -145,14 +149,10 @@
             # delayed acks.  If we send a very large string, only a
             # portion of it will actually be delivered at a time.
 
-            # We chose 60000 as the socket limit by looking at the
-            # largest strings that we could pass to send() without
-            # blocking.
-
             l = 0
             for i in range(len(output)):
                 l += len(output[i])
-                if l > 60000:
+                if l > SEND_SIZE:
                     break
 
             i += 1
@@ -167,8 +167,6 @@
                     break # we couldn't write anything
                 raise
             if n < len(v):
-                # XXX It's unfortunate that we end up making many
-                # slices of a large string.
                 output.insert(0, v[n:])
                 break # we can't write any more
 
@@ -191,7 +189,12 @@
                 )
         # do two separate appends to avoid copying the message string
         self.__output.append(struct.pack(">i", len(message)))
-        self.__output.append(message)
+        if len(message) <= SEND_SIZE:
+            self.__output.append(message)
+        else:
+            for i in range(0, len(message), SEND_SIZE):
+                self.__output.append(message[i:i+SEND_SIZE])
+            
 
     def close(self):
         if self.__closed is None: