From 3960e6495ee95d87b3da6b03aedcb3ab34a9ef58 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 16 Dec 2012 00:47:46 +0800 Subject: [PATCH] replace send with sendall --- local.py | 10 ++++++++-- server.py | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/local.py b/local.py index e45fffe..3abc8a5 100755 --- a/local.py +++ b/local.py @@ -54,10 +54,16 @@ class Socks5Server(SocketServer.StreamRequestHandler): while True: r, w, e = select.select(fdset, [], []) if sock in r: - if remote.send(self.encrypt(sock.recv(4096))) <= 0: + data = sock.recv(4096) + if data <= 0: + break + if remote.sendall(self.encrypt(data)) is not None: break if remote in r: - if sock.send(self.decrypt(remote.recv(4096))) <= 0: + data = remote.recv(4096) + if data <= 0: + break + if sock.sendall(self.decrypt(data)) is not None: break finally: sock.close() diff --git a/server.py b/server.py index 670c6d8..10ad75d 100755 --- a/server.py +++ b/server.py @@ -54,10 +54,16 @@ class Socks5Server(SocketServer.StreamRequestHandler): while True: r, w, e = select.select(fdset, [], []) if sock in r: - if remote.send(self.decrypt(sock.recv(4096))) <= 0: + data = sock.recv(4096) + if data <= 0: + break + if remote.sendall(self.decrypt(data)) is not None: break if remote in r: - if sock.send(self.encrypt(remote.recv(4096))) <= 0: + data = remote.recv(4096) + if data <= 0: + break + if sock.sendall(self.encrypt(data)) is not None: break finally: sock.close()