Browse Source

fix infinite loop bug

1.4
clowwindy 12 years ago
parent
commit
480c9ec51e
  1. 12
      local.py
  2. 14
      server.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

@ -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…
Cancel
Save