SVN: ZODB/branches/jim-zrpc/src/ZEO/zrpc/connection.py message ids are only needed for 2-way calls.

Jim Fulton <[email protected]>
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20100127195725.39AA29417C__36186.5243212835$1264622258$gmane$org@cvs.zope.org>
Log message for revision 108580:
  message ids are only needed for 2-way calls.
  
  Only clients send 2-way messages, so only clients need to generate
  msgids.
  

Changed:
  U   ZODB/branches/jim-zrpc/src/ZEO/zrpc/connection.py

-=-
Modified: ZODB/branches/jim-zrpc/src/ZEO/zrpc/connection.py
===================================================================
--- ZODB/branches/jim-zrpc/src/ZEO/zrpc/connection.py	2010-01-27 19:22:09 UTC (rev 108579)
+++ ZODB/branches/jim-zrpc/src/ZEO/zrpc/connection.py	2010-01-27 19:57:24 UTC (rev 108580)
@@ -424,10 +424,6 @@
         # The singleton dict is a socket map containing only this object.
         self._singleton = {self._fileno: self}
 
-        # msgid_lock guards access to msgid
-        self.msgid = 0
-        self.msgid_lock = threading.Lock()
-
         # replies_cond is used to block when a synchronous call is
         # waiting for a response
         self.replies_cond = threading.Condition()
@@ -637,21 +633,13 @@
         else:
             self.__super_setSessionKey(key)
 
-    # The next two public methods (call and callAsync) are used by
-    # clients to invoke methods on remote objects
-
-    def __new_msgid(self):
-        self.msgid_lock.acquire()
-        try:
-            msgid = self.msgid
-            self.msgid = self.msgid + 1
-            return msgid
-        finally:
-            self.msgid_lock.release()
-
     def send_call(self, method, args, async=False):
         # send a message and return its msgid
-        msgid = self.__new_msgid()
+        if async:
+            msgid = 0
+        else:
+            msgid = self._new_msgid()
+
         if debug_zrpc:
             self.log("send msg: %d, %d, %s, ..." % (msgid, async, method),
                      level=TRACE)
@@ -765,6 +753,10 @@
         self.queue_output = True
         self.queued_messages = []
 
+        # msgid_lock guards access to msgid
+        self.msgid = 0
+        self.msgid_lock = threading.Lock()
+
         self.__super_init(sock, addr, None, tag='C', map=client_map)
         client_trigger.pull_trigger()
 
@@ -810,6 +802,15 @@
         finally:
             self.output_lock.release()
 
+    def _new_msgid(self):
+        self.msgid_lock.acquire()
+        try:
+            msgid = self.msgid
+            self.msgid = self.msgid + 1
+            return msgid
+        finally:
+            self.msgid_lock.release()
+
     def call(self, method, *args):
         if self.closed:
             raise DisconnectedError()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.