mirror of
https://git.deluge-torrent.org/deluge
synced 2025-09-02 08:05:36 +00:00
If a exported method returns a deferred, the rpcserver will now wait for it to fire before sending either the RPC_RESPONSE or RPC_ERROR message back to the client
This commit is contained in:
parent
85c32f0403
commit
a8b83281ab
1 changed files with 18 additions and 2 deletions
|
@ -42,7 +42,7 @@ import stat
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from twisted.internet.protocol import Factory, Protocol
|
from twisted.internet.protocol import Factory, Protocol
|
||||||
from twisted.internet import ssl, reactor
|
from twisted.internet import ssl, reactor, defer
|
||||||
|
|
||||||
from OpenSSL import crypto, SSL
|
from OpenSSL import crypto, SSL
|
||||||
from types import FunctionType
|
from types import FunctionType
|
||||||
|
@ -272,7 +272,23 @@ class DelugeRPCProtocol(Protocol):
|
||||||
if not isinstance(e, DelugeError):
|
if not isinstance(e, DelugeError):
|
||||||
log.exception("Exception calling RPC request: %s", e)
|
log.exception("Exception calling RPC request: %s", e)
|
||||||
else:
|
else:
|
||||||
self.sendData((RPC_RESPONSE, request_id, ret))
|
# Check if the return value is a deferred, since we'll need to
|
||||||
|
# wait for it to fire before sending the RPC_RESPONSE
|
||||||
|
if isinstance(ret, defer.Deferred):
|
||||||
|
def on_success(result):
|
||||||
|
self.sendData((RPC_RESPONSE, request_id, ret))
|
||||||
|
return result
|
||||||
|
|
||||||
|
def on_fail(failure):
|
||||||
|
try:
|
||||||
|
failure.raiseException()
|
||||||
|
except Exception, e:
|
||||||
|
sendError()
|
||||||
|
return failure
|
||||||
|
|
||||||
|
ret.addCallbacks(on_success, on_fail)
|
||||||
|
else:
|
||||||
|
self.sendData((RPC_RESPONSE, request_id, ret))
|
||||||
|
|
||||||
class RPCServer(component.Component):
|
class RPCServer(component.Component):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue