mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-12 19:28:42 +00:00
Do not have signalmanager/receiver connections linger by setting the
SO_LINGER sockopt.
This commit is contained in:
parent
03c6e5ef9b
commit
32db5e2c5d
2 changed files with 28 additions and 4 deletions
|
@ -25,12 +25,24 @@
|
||||||
|
|
||||||
import deluge.xmlrpclib as xmlrpclib
|
import deluge.xmlrpclib as xmlrpclib
|
||||||
import socket
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
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):
|
class SignalManager(component.Component):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
component.Component.__init__(self, "SignalManager")
|
component.Component.__init__(self, "SignalManager")
|
||||||
|
@ -68,7 +80,9 @@ class SignalManager(component.Component):
|
||||||
"""Registers a client to emit signals to."""
|
"""Registers a client to emit signals to."""
|
||||||
uri = "http://" + str(address) + ":" + str(port)
|
uri = "http://" + str(address) + ":" + str(port)
|
||||||
log.debug("Registering %s as a signal reciever..", uri)
|
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):
|
def emit(self, signal, *data):
|
||||||
# Run the handlers
|
# Run the handlers
|
||||||
|
@ -92,4 +106,3 @@ class SignalManager(component.Component):
|
||||||
else:
|
else:
|
||||||
log.info("Removing %s because it couldn't be reached..", uri)
|
log.info("Removing %s because it couldn't be reached..", uri)
|
||||||
del self.clients[uri]
|
del self.clients[uri]
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
import socket
|
import socket
|
||||||
|
import struct
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
|
@ -35,6 +36,17 @@ import deluge.common
|
||||||
import deluge.error
|
import deluge.error
|
||||||
from deluge.log import LOG as log
|
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):
|
class CoreProxy(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
"new_core" : (
|
"new_core" : (
|
||||||
|
@ -134,7 +146,7 @@ class CoreProxy(gobject.GObject):
|
||||||
def get_rpc_core(self):
|
def get_rpc_core(self):
|
||||||
if self.rpc_core is None and self._uri is not None:
|
if self.rpc_core is None and self._uri is not None:
|
||||||
log.debug("Creating ServerProxy..")
|
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 = xmlrpclib.MultiCall(self.rpc_core)
|
||||||
self._multi_timer = gobject.timeout_add(200, self.do_multicall)
|
self._multi_timer = gobject.timeout_add(200, self.do_multicall)
|
||||||
# Call any callbacks registered
|
# Call any callbacks registered
|
||||||
|
@ -306,4 +318,3 @@ class AClient(BaseClient):
|
||||||
|
|
||||||
sclient = SClient()
|
sclient = SClient()
|
||||||
aclient = AClient()
|
aclient = AClient()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue