Browse Source

add nodelay

1.4
clowwindy 11 years ago
parent
commit
355307e5ef
  1. 3
      .gitignore
  2. 2
      shadowsocks/local.py
  3. 2
      shadowsocks/server.py

3
.gitignore

@ -25,3 +25,6 @@ pip-log.txt
#Mr Developer #Mr Developer
.mr.developer.cfg .mr.developer.cfg
.DS_Store
.idea

2
shadowsocks/local.py

@ -121,6 +121,7 @@ class Socks5Server(SocketServer.StreamRequestHandler):
try: try:
self.encryptor = encrypt.Encryptor(KEY, METHOD) self.encryptor = encrypt.Encryptor(KEY, METHOD)
sock = self.connection sock = self.connection
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
data = sock.recv(262) data = sock.recv(262)
if not data: if not data:
sock.close() sock.close()
@ -202,6 +203,7 @@ class Socks5Server(SocketServer.StreamRequestHandler):
# reply immediately # reply immediately
aServer, aPort = self.getServer() aServer, aPort = self.getServer()
remote = socket.create_connection((aServer, aPort)) remote = socket.create_connection((aServer, aPort))
remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
self.send_encrypt(remote, addr_to_send) self.send_encrypt(remote, addr_to_send)
logging.info('connecting %s:%d' % (addr, port[0])) logging.info('connecting %s:%d' % (addr, port[0]))
except socket.error, e: except socket.error, e:

2
shadowsocks/server.py

@ -102,6 +102,7 @@ class Socks5Server(SocketServer.StreamRequestHandler):
self.encryptor = encrypt.Encryptor(self.server.key, self.encryptor = encrypt.Encryptor(self.server.key,
self.server.method) self.server.method)
sock = self.connection sock = self.connection
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
iv_len = self.encryptor.iv_len() iv_len = self.encryptor.iv_len()
data = sock.recv(iv_len) data = sock.recv(iv_len)
if iv_len > 0 and not data: if iv_len > 0 and not data:
@ -130,6 +131,7 @@ class Socks5Server(SocketServer.StreamRequestHandler):
try: try:
logging.info('connecting %s:%d' % (addr, port[0])) logging.info('connecting %s:%d' % (addr, port[0]))
remote = socket.create_connection((addr, port[0])) remote = socket.create_connection((addr, port[0]))
remote.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
except socket.error, e: except socket.error, e:
# Connection refused # Connection refused
logging.warn(e) logging.warn(e)

Loading…
Cancel
Save