Commit bf5f5ec4 authored by Jeremy Hylton's avatar Jeremy Hylton

Rename _do_async_loop() and _do_async_poll() to wait() and poll().

Repair comments in _call() about how wait() handles reply lock.
parent d7a558d1
...@@ -248,7 +248,7 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -248,7 +248,7 @@ class Connection(smac.SizedMessageAsyncConnection):
def send_reply(self, msgid, ret): def send_reply(self, msgid, ret):
msg = self.marshal.encode(msgid, 0, REPLY, ret) msg = self.marshal.encode(msgid, 0, REPLY, ret)
self.message_output(msg) self.message_output(msg)
self._do_async_poll() self.poll()
def return_error(self, msgid, flags, err_type, err_value): def return_error(self, msgid, flags, err_type, err_value):
if flags is None: if flags is None:
...@@ -266,7 +266,7 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -266,7 +266,7 @@ class Connection(smac.SizedMessageAsyncConnection):
err = ZRPCError("Couldn't pickle error %s" % `err_value`) err = ZRPCError("Couldn't pickle error %s" % `err_value`)
msg = self.marshal.encode(msgid, 0, REPLY, (ZRPCError, err)) msg = self.marshal.encode(msgid, 0, REPLY, (ZRPCError, err))
self.message_output(msg) self.message_output(msg)
self._do_async_poll() self.poll()
# The next two public methods (call and callAsync) are used by # The next two public methods (call and callAsync) are used by
# clients to invoke methods on remote objects # clients to invoke methods on remote objects
...@@ -287,12 +287,10 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -287,12 +287,10 @@ class Connection(smac.SizedMessageAsyncConnection):
log("send msg: %d, 0, %s, ..." % (msgid, method)) log("send msg: %d, 0, %s, ..." % (msgid, method))
self.message_output(self.marshal.encode(msgid, 0, method, args)) self.message_output(self.marshal.encode(msgid, 0, method, args))
# XXX implementation of promises starts here # XXX implementation of promises would start here
self.__reply = None self.__reply = None
# reply lock is currently held self.wait() # will release reply lock before returning
self._do_async_loop()
# reply lock is held again...
r_msgid, r_flags, r_args = self.__reply r_msgid, r_flags, r_args = self.__reply
self.__reply_lock.acquire() self.__reply_lock.acquire()
assert r_msgid == msgid, "%s != %s: %s" % (r_msgid, msgid, r_args) assert r_msgid == msgid, "%s != %s: %s" % (r_msgid, msgid, r_args)
...@@ -318,10 +316,7 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -318,10 +316,7 @@ class Connection(smac.SizedMessageAsyncConnection):
if __debug__: if __debug__:
log("send msg: %d, %d, %s, ..." % (msgid, ASYNC, method)) log("send msg: %d, %d, %s, ..." % (msgid, ASYNC, method))
self.message_output(self.marshal.encode(msgid, ASYNC, method, args)) self.message_output(self.marshal.encode(msgid, ASYNC, method, args))
# XXX The message won't go out right away in this case. It self.poll()
# will wait for the asyncore loop to get control again. Seems
# okay to comment our for now, but need to understand better.
self._do_async_poll()
# handle IO, possibly in async mode # handle IO, possibly in async mode
...@@ -341,11 +336,10 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -341,11 +336,10 @@ class Connection(smac.SizedMessageAsyncConnection):
else: else:
return 0 return 0
def _do_async_loop(self): def wait(self):
"Invoke asyncore mainloop and wait for reply." """Invoke asyncore mainloop and wait for reply."""
if __debug__: if __debug__:
log("_do_async_loop() async=%d" % self.is_async(), log("wait() async=%d" % self.is_async(), level=zLOG.TRACE)
level=zLOG.DEBUG)
if self.is_async(): if self.is_async():
self.trigger.pull_trigger() self.trigger.pull_trigger()
self.__reply_lock.acquire() self.__reply_lock.acquire()
...@@ -364,12 +358,10 @@ class Connection(smac.SizedMessageAsyncConnection): ...@@ -364,12 +358,10 @@ class Connection(smac.SizedMessageAsyncConnection):
raise DisconnectedError() raise DisconnectedError()
self.__reply_lock.release() self.__reply_lock.release()
def _do_async_poll(self, wait_for_reply=0): def poll(self, wait_for_reply=0):
"Invoke asyncore mainloop to get pending message out." """Invoke asyncore mainloop to get pending message out."""
if __debug__: if __debug__:
log("_do_async_poll(), async=%d" % self.is_async(), log("poll(), async=%d" % self.is_async(), level=zLOG.TRACE)
level=zLOG.DEBUG)
if self.is_async(): if self.is_async():
self.trigger.pull_trigger() self.trigger.pull_trigger()
else: else:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment