diff --git a/shadowsocks/local.py b/shadowsocks/local.py index b57da4d..2b7d7f4 100755 --- a/shadowsocks/local.py +++ b/shadowsocks/local.py @@ -202,9 +202,13 @@ class Socks5Server(SocketServer.StreamRequestHandler): self.wfile.write(reply) # reply immediately aServer, aPort = self.getServer() - remote = socket.create_connection((aServer, aPort)) + MSG_FASTOPEN = 0x20000000 + remote = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + # remote = socket.create_connection((aServer, aPort)) remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) - self.send_encrypt(remote, addr_to_send) + data = self.encrypt(addr_to_send) + remote.sendto(data, MSG_FASTOPEN, (aServer, aPort)) + # self.send_encrypt(remote, addr_to_send) logging.info('connecting %s:%d' % (addr, port[0])) except socket.error, e: logging.warn(e) diff --git a/shadowsocks/server.py b/shadowsocks/server.py index ef77184..1d693e9 100755 --- a/shadowsocks/server.py +++ b/shadowsocks/server.py @@ -65,6 +65,10 @@ def send_all(sock, data): class ThreadingTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer): allow_reuse_address = True + def server_activate(self): + self.socket.setsockopt(socket.SOL_TCP, 23, 5) + self.socket.listen(self.request_queue_size) + class Socks5Server(SocketServer.StreamRequestHandler): def handle_tcp(self, sock, remote):