Do not have signalmanager/receiver connections linger by setting the

SO_LINGER sockopt.
This commit is contained in:
Andrew Resch 2008-11-29 19:07:28 +00:00
parent 03c6e5ef9b
commit 32db5e2c5d
2 changed files with 28 additions and 4 deletions

View File

@ -25,12 +25,24 @@
import deluge.xmlrpclib as xmlrpclib
import socket
import struct
import gobject
import deluge.component as component
from deluge.log import LOG as log
class Transport(xmlrpclib.Transport):
def make_connection(self, host):
# create a HTTP connection object from a host descriptor
import httplib
host, extra_headers, x509 = self.get_host_info(host)
h = httplib.HTTP(host)
h._conn.connect()
h._conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack('ii', 1, 0))
return h
class SignalManager(component.Component):
def __init__(self):
component.Component.__init__(self, "SignalManager")
@ -68,7 +80,9 @@ class SignalManager(component.Component):
"""Registers a client to emit signals to."""
uri = "http://" + str(address) + ":" + str(port)
log.debug("Registering %s as a signal reciever..", uri)
self.clients[uri] = xmlrpclib.ServerProxy(uri)
self.clients[uri] = xmlrpclib.ServerProxy(uri, transport=Transport())
#self.clients[uri].socket.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
# struct.pack('ii', 1, 0))
def emit(self, signal, *data):
# Run the handlers
@ -92,4 +106,3 @@ class SignalManager(component.Component):
else:
log.info("Removing %s because it couldn't be reached..", uri)
del self.clients[uri]

View File

@ -26,6 +26,7 @@
import os.path
import socket
import struct
import gobject
@ -35,6 +36,17 @@ import deluge.common
import deluge.error
from deluge.log import LOG as log
class Transport(xmlrpclib.Transport):
def make_connection(self, host):
# create a HTTP connection object from a host descriptor
import httplib
host, extra_headers, x509 = self.get_host_info(host)
h = httplib.HTTP(host)
h._conn.connect()
h._conn.sock.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,
struct.pack('ii', 1, 0))
return h
class CoreProxy(gobject.GObject):
__gsignals__ = {
"new_core" : (
@ -134,7 +146,7 @@ class CoreProxy(gobject.GObject):
def get_rpc_core(self):
if self.rpc_core is None and self._uri is not None:
log.debug("Creating ServerProxy..")
self.rpc_core = xmlrpclib.ServerProxy(self._uri.replace("localhost", "127.0.0.1"), allow_none=True)
self.rpc_core = xmlrpclib.ServerProxy(self._uri.replace("localhost", "127.0.0.1"), allow_none=True, transport=Transport())
self._multi = xmlrpclib.MultiCall(self.rpc_core)
self._multi_timer = gobject.timeout_add(200, self.do_multicall)
# Call any callbacks registered
@ -306,4 +318,3 @@ class AClient(BaseClient):
sclient = SClient()
aclient = AClient()