summaryrefslogtreecommitdiffstats
path: root/pyload/plugin/addon/ClickAndLoad.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/plugin/addon/ClickAndLoad.py')
-rw-r--r--pyload/plugin/addon/ClickAndLoad.py86
1 files changed, 27 insertions, 59 deletions
diff --git a/pyload/plugin/addon/ClickAndLoad.py b/pyload/plugin/addon/ClickAndLoad.py
index 98e650d15..c5042ede6 100644
--- a/pyload/plugin/addon/ClickAndLoad.py
+++ b/pyload/plugin/addon/ClickAndLoad.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
import socket
+import time
from threading import Lock
@@ -18,48 +19,15 @@ def forward(source, destination):
destination.shutdown(socket.SHUT_WR)
-#: create_connection wrapper for python 2.5 socket module
-def create_connection(address, timeout=object(), source_address=None):
- if hasattr(socket, 'create_connection'):
- if type(timeout) == object:
- timeout = socket._GLOBAL_DEFAULT_TIMEOUT
-
- return socket.create_connection(address, timeout, source_address)
-
- else:
- host, port = address
- err = None
- for res in getaddrinfo(host, port, 0, SOCK_STREAM):
- af, socktype, proto, canonname, sa = res
- sock = None
- try:
- sock = socket(af, socktype, proto)
- if type(timeout) != object:
- sock.settimeout(timeout)
- if source_address:
- sock.bind(source_address)
- sock.connect(sa)
- return sock
-
- except socket.error, _:
- err = _
- if sock is not None:
- sock.close()
-
- if err is not None:
- raise err
- else:
- raise socket.error("getaddrinfo returns an empty list")
-
-
+#@TODO: IPv6 support
class ClickAndLoad(Addon):
__name = "ClickAndLoad"
__type = "addon"
- __version = "0.35"
+ __version = "0.37"
__config = [("activated", "bool", "Activated" , True),
- ("port" , "int" , "Port" , 9666),
- ("extern" , "bool", "Listen on the public network interface", True)]
+ ("port" , "int" , "Port" , 9666),
+ ("extern" , "bool", "Listen on the public network interface", True)]
__description = """Click'N'Load addon plugin"""
__license = "GPLv3"
@@ -71,7 +39,7 @@ class ClickAndLoad(Addon):
if not self.config['webinterface']['activated']:
return
- ip = socket.gethostbyname(socket.gethostname()) if self.getConfig("extern") else "127.0.0.1"
+ ip = "" if self.getConfig("extern") else "127.0.0.1"
webport = int(self.config['webinterface']['port'])
cnlport = self.getConfig('port')
@@ -80,6 +48,7 @@ class ClickAndLoad(Addon):
@threaded
def proxy(self, ip, webport, cnlport):
+ self.logInfo(_("Proxy listening on %s:%s") % (ip, cnlport))
self.manager.startThread(self._server, ip, webport, cnlport)
lock = Lock()
lock.acquire()
@@ -88,32 +57,31 @@ class ClickAndLoad(Addon):
def _server(self, ip, webport, cnlport, thread):
try:
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- server_socket.bind((ip, cnlport))
- server_socket.listen(5)
+ try:
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- while True:
- client_socket = server_socket.accept()[0]
- dock_socket = create_connection(("127.0.0.1", webport))
+ server_socket.bind((ip, cnlport))
+ server_socket.listen(5)
- self.manager.startThread(forward, dock_socket, client_socket)
- self.manager.startThread(forward, client_socket, dock_socket)
+ while True:
+ client_socket = server_socket.accept()[0]
+ dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- except socket.error, e:
- self.logDebug(e)
- self._server(ip, webport, cnlport, thread)
+ dock_socket.connect(("127.0.0.1", webport))
- except Exception, e:
- self.logError(e)
+ self.manager.startThread(forward, dock_socket, client_socket)
+ self.manager.startThread(forward, client_socket, dock_socket)
- try:
+ except socket.timeout:
+ self.logDebug("Connection timed out, retrying...")
+ return self._server(ip, webport, cnlport, thread)
+
+ finally:
+ server_socket.close()
client_socket.close()
dock_socket.close()
- except Exception:
- pass
- try:
- server_socket.close()
- except Exception:
- pass
+ except socket.error, e:
+ self.logError(e)
+ time.sleep(120)
+ self._server(ip, webport, cnlport, thread)