Windows ipc fixes

This commit is contained in:
Andrew Resch 2008-07-17 23:55:53 +00:00
parent ed9b472615
commit b62dfde447
2 changed files with 25 additions and 27 deletions

View File

@ -44,13 +44,14 @@ class Signals(component.Component):
component.Component.__init__(self, "Signals")
self.receiver = SignalReceiver()
self.config = ConfigManager("gtkui.conf")
self.config["signal_port"] = self.receiver.get_port()
self.config.save()
def start(self):
if not client.is_localhost():
self.receiver.set_remote(True)
self.receiver.run()
self.config["signal_port"] = self.receiver.get_port()
self.receiver.connect_to_signal("torrent_added",
self.torrent_added_signal)
self.receiver.connect_to_signal("torrent_removed",

View File

@ -50,8 +50,6 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
def __init__(self):
log.debug("SignalReceiver init..")
# gobject.threads_init()
# Set to true so that the receiver thread will exit
self._shutdown = False
@ -59,7 +57,29 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
self.emitted_signals = []
self.remote = False
# Setup the xmlrpc server
host = "localhost"
if self.remote == True:
host = ""
server_ready = False
while not server_ready:
port = random.randint(40000, 65535)
try:
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
self, (host, port), logRequests=False, allow_none=True)
except socket.error, e:
log.debug("Trying again with another port: %s", e)
except:
log.error("Could not start SignalReceiver XMLRPC server: %s", e)
sys.exit(0)
else:
self.port = port
server_ready = True
# Register the emit_signal function
self.register_function(self.emit_signal)
def shutdown(self):
"""Shutdowns receiver thread"""
@ -83,29 +103,6 @@ class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
def run(self):
"""This gets called when we start the thread"""
host = "localhost"
if self.remote == True:
host = ""
# Setup the xmlrpc server
server_ready = False
while not server_ready:
port = random.randint(40000, 65535)
try:
SimpleXMLRPCServer.SimpleXMLRPCServer.__init__(
self, (host, port), logRequests=False, allow_none=True)
except socket.error, e:
log.debug("Trying again with another port: %s", e)
except:
log.error("Could not start SignalReceiver XMLRPC server: %s", e)
sys.exit(0)
else:
self.port = port
server_ready = True
# Register the emit_signal function
self.register_function(self.emit_signal)
# Register the signal receiver with the core
client.register_client(str(self.port))