summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2015-03-02 00:39:51 +0100
committerGravatar Walter Purcaro <vuolter@gmail.com> 2015-03-02 00:39:51 +0100
commit5ea0fe898b435a5654e0a14172025779c82182d6 (patch)
tree6c40199599139a5650bd26e44f0afd5ddd154c0b /module
parent[Extractor] Use self.target (diff)
downloadpyload-5ea0fe898b435a5654e0a14172025779c82182d6.tar.xz
[ClickAndLoad] Revert and improve
Diffstat (limited to 'module')
-rw-r--r--module/plugins/hooks/ClickAndLoad.py50
1 files changed, 24 insertions, 26 deletions
diff --git a/module/plugins/hooks/ClickAndLoad.py b/module/plugins/hooks/ClickAndLoad.py
index 5b21aec96..1a7dec6ac 100644
--- a/module/plugins/hooks/ClickAndLoad.py
+++ b/module/plugins/hooks/ClickAndLoad.py
@@ -16,6 +16,7 @@ def forward(source, destination):
destination.sendall(bufdata)
bufdata = source.recv(bufsize)
finally:
+ source.shutdown(socket.SHUT_RD)
destination.shutdown(socket.SHUT_WR)
@@ -23,13 +24,13 @@ def forward(source, destination):
class ClickAndLoad(Hook):
__name__ = "ClickAndLoad"
__type__ = "hook"
- __version__ = "0.37"
+ __version__ = "0.38"
__config__ = [("activated", "bool", "Activated" , True),
("port" , "int" , "Port" , 9666),
("extern" , "bool", "Listen on the public network interface", True)]
- __description__ = """Click'N'Load hook plugin"""
+ __description__ = """Click'n'Load hook plugin"""
__license__ = "GPLv3"
__authors__ = [("RaNaN", "RaNaN@pyload.de"),
("Walter Purcaro", "vuolter@gmail.com")]
@@ -45,7 +46,7 @@ class ClickAndLoad(Hook):
return
ip = "" if self.getConfig("extern") else "127.0.0.1"
- webport = int(self.config['webinterface']['port'])
+ webport = self.config['webinterface']['port']
cnlport = self.getConfig('port')
self.proxy(ip, webport, cnlport)
@@ -54,39 +55,36 @@ class ClickAndLoad(Hook):
@threaded
def proxy(self, ip, webport, cnlport):
self.logInfo(_("Proxy listening on %s:%s") % (ip or "0.0.0.0", cnlport))
- self.manager.startThread(self._server, ip, webport, cnlport)
+
+ self._server(ip, webport, cnlport)
+
lock = Lock()
lock.acquire()
lock.acquire()
- def _server(self, ip, webport, cnlport, thread):
+ @threaded
+ def _server(self, ip, webport, cnlport):
try:
- try:
- server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ dock_socket.bind((ip, cnlport))
+ dock_socket.listen(1)
- server_socket.bind((ip, cnlport))
- server_socket.listen(5)
+ while True:
+ client_socket, client_addr = dock_socket.accept()
+ self.logDebug("Connection from: %s" % client_addr)
- while True:
- client_socket = server_socket.accept()[0]
- dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-
- dock_socket.connect(("127.0.0.1", webport))
-
- self.manager.startThread(forward, dock_socket, client_socket)
- self.manager.startThread(forward, client_socket, dock_socket)
+ server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ server_socket.connect(("127.0.0.1", webport))
- except socket.timeout:
- self.logDebug("Connection timed out, retrying...")
- return self._server(ip, webport, cnlport, thread)
+ self.manager.startThread(forward, client_socket, server_socket)
+ self.manager.startThread(forward, server_socket, client_socket)
- finally:
- server_socket.close()
- client_socket.close()
- dock_socket.close()
+ except socket.timeout:
+ self.logDebug("Connection timed out, retrying...")
+ return self._server(ip, webport, cnlport)
except socket.error, e:
self.logError(e)
- time.sleep(120)
- self._server(ip, webport, cnlport, thread)
+ time.sleep(240)
+ return self._server(ip, webport, cnlport)