[Neo-report] r2657 gregory - /trunk/neo/lib/protocol.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Mar 1 15:54:19 CET 2011


Author: gregory
Date: Tue Mar  1 15:54:18 2011
New Revision: 2657

Log:
Remove overhead when transmitting None addresses.

Use a marker meaning "no content", AF_UNSPEC seems appropriate for this
kind of usage.

Modified:
    trunk/neo/lib/protocol.py

Modified: trunk/neo/lib/protocol.py
==============================================================================
--- trunk/neo/lib/protocol.py [iso-8859-1] (original)
+++ trunk/neo/lib/protocol.py [iso-8859-1] Tue Mar  1 15:54:18 2011
@@ -111,7 +111,7 @@ INVALID_UUID = '\0' * 16
 INVALID_TID = '\xff' * 8
 INVALID_OID = '\xff' * 8
 INVALID_PARTITION = 0xffffffff
-INVALID_ADDRESS = ('0.0.0.0', 0)
+INVALID_ADDRESS_TYPE = socket.AF_UNSPEC
 ZERO_TID = '\0' * 8
 ZERO_OID = '\0' * 8
 OID_LEN = len(INVALID_OID)
@@ -436,7 +436,8 @@ class PAddress(PStructItem):
 
     def _encode(self, writer, address):
         if address is None:
-            address = INVALID_ADDRESS
+            writer(self.pack(INVALID_ADDRESS_TYPE))
+            return
         af_type = getAddressType(address)
         writer(self.pack(af_type))
         encoder = self.address_format_dict[af_type]
@@ -444,10 +445,10 @@ class PAddress(PStructItem):
 
     def _decode(self, reader):
         af_type  = self.unpack(reader(self.size))[0]
+        if af_type == INVALID_ADDRESS_TYPE:
+            return None
         decoder = self.address_format_dict[af_type]
         host, port = decoder.decode(reader)
-        if (host, port) == INVALID_ADDRESS:
-            return None
         return (host, port)
 
 class PString(PStructItem):




More information about the Neo-report mailing list