From 355307e5ef948030c8be3b4ef7a0145cec082817 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 1 May 2014 11:44:36 +0800 Subject: [PATCH] add nodelay --- .gitignore | 3 +++ shadowsocks/local.py | 2 ++ shadowsocks/server.py | 2 ++ 3 files changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index f24cd99..357232f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,6 @@ pip-log.txt #Mr Developer .mr.developer.cfg + +.DS_Store +.idea diff --git a/shadowsocks/local.py b/shadowsocks/local.py index e54484e..b57da4d 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -121,6 +121,7 @@ class Socks5Server(SocketServer.StreamRequestHandler): try: self.encryptor = encrypt.Encryptor(KEY, METHOD) sock = self.connection + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) data = sock.recv(262) if not data: sock.close() @@ -202,6 +203,7 @@ class Socks5Server(SocketServer.StreamRequestHandler): # reply immediately aServer, aPort = self.getServer() remote = socket.create_connection((aServer, aPort)) + remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) self.send_encrypt(remote, addr_to_send) logging.info('connecting %s:%d' % (addr, port[0])) except socket.error, e: diff --git a/shadowsocks/server.py b/shadowsocks/server.py index 1574b79..ef77184 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -102,6 +102,7 @@ class Socks5Server(SocketServer.StreamRequestHandler): self.encryptor = encrypt.Encryptor(self.server.key, self.server.method) sock = self.connection + sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) iv_len = self.encryptor.iv_len() data = sock.recv(iv_len) if iv_len > 0 and not data: @@ -130,6 +131,7 @@ class Socks5Server(SocketServer.StreamRequestHandler): try: logging.info('connecting %s:%d' % (addr, port[0])) remote = socket.create_connection((addr, port[0])) + remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) except socket.error, e: # Connection refused logging.warn(e)