fix infinite loop bug
This commit is contained in:
parent
004e9292f4
commit
480c9ec51e
2 changed files with 17 additions and 9 deletions
12
local.py
12
local.py
|
@ -72,15 +72,19 @@ class Socks5Server(SocketServer.StreamRequestHandler):
|
|||
r, w, e = select.select(fdset, [], [])
|
||||
if sock in r:
|
||||
data = sock.recv(4096)
|
||||
if data <= 0:
|
||||
if len(data) <= 0:
|
||||
break
|
||||
send_all(remote, self.encrypt(data))
|
||||
result = send_all(remote, self.encrypt(data))
|
||||
if result < len(data):
|
||||
raise Exception('failed to send all data')
|
||||
|
||||
if remote in r:
|
||||
data = remote.recv(4096)
|
||||
if data <= 0:
|
||||
if len(data) <= 0:
|
||||
break
|
||||
send_all(sock, self.decrypt(data))
|
||||
result = send_all(sock, self.decrypt(data))
|
||||
if result < len(data):
|
||||
raise Exception('failed to send all data')
|
||||
finally:
|
||||
sock.close()
|
||||
remote.close()
|
||||
|
|
14
server.py
14
server.py
|
@ -60,7 +60,6 @@ def send_all(sock, data):
|
|||
if bytes_sent == len(data):
|
||||
return bytes_sent
|
||||
|
||||
|
||||
class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
|
||||
allow_reuse_address = True
|
||||
|
||||
|
@ -73,14 +72,19 @@ class Socks5Server(SocketServer.StreamRequestHandler):
|
|||
r, w, e = select.select(fdset, [], [])
|
||||
if sock in r:
|
||||
data = sock.recv(4096)
|
||||
if data <= 0:
|
||||
if len(data) <= 0:
|
||||
break
|
||||
send_all(remote, self.decrypt(data))
|
||||
result = send_all(remote, self.decrypt(data))
|
||||
if result < len(data):
|
||||
raise Exception('failed to send all data')
|
||||
if remote in r:
|
||||
data = remote.recv(4096)
|
||||
if data <= 0:
|
||||
if len(data) <= 0:
|
||||
break
|
||||
send_all(sock, self.encrypt(data))
|
||||
result = send_all(sock, self.encrypt(data))
|
||||
if result < len(data):
|
||||
raise Exception('failed to send all data')
|
||||
|
||||
finally:
|
||||
sock.close()
|
||||
remote.close()
|
||||
|
|
Loading…
Reference in a new issue