From 92722c2ea96c0fa59a4c8e182d3993cdf018f361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=B4=E5=A8=83=E9=85=B1?= Date: Mon, 29 May 2017 08:42:57 +0800 Subject: [PATCH] refine _get_read_size --- shadowsocks/tcprelay.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/shadowsocks/tcprelay.py b/shadowsocks/tcprelay.py index 65df4c8..661f359 100644 --- a/shadowsocks/tcprelay.py +++ b/shadowsocks/tcprelay.py @@ -832,15 +832,15 @@ class TCPRelayHandler(object): buffer_size = len(sock.recv(recv_buffer_size, socket.MSG_PEEK)) if up: buffer_size = min(buffer_size, self._recv_u_max_size) - self._recv_u_max_size = min(self._recv_u_max_size + TCP_MSS, BUF_SIZE) + self._recv_u_max_size = min(self._recv_u_max_size + self._tcp_mss - self._overhead, BUF_SIZE) else: buffer_size = min(buffer_size, self._recv_d_max_size) - self._recv_d_max_size = min(self._recv_d_max_size + TCP_MSS, BUF_SIZE) + self._recv_d_max_size = min(self._recv_d_max_size + self._tcp_mss - self._overhead, BUF_SIZE) if buffer_size == recv_buffer_size: return buffer_size - s = buffer_size % self._tcp_mss + self._overhead - if s > self._tcp_mss: - return buffer_size - (s - self._tcp_mss) + frame_size = self._tcp_mss - self._overhead + if buffer_size > frame_size: + buffer_size = int(buffer_size / frame_size) * frame_size return buffer_size def _on_local_read(self): @@ -1074,7 +1074,7 @@ class TCPRelayHandler(object): handle = True self._on_remote_read(sock == self._remote_sock) else: - self._recv_d_max_size = TCP_MSS + self._recv_d_max_size = self._tcp_mss - self._overhead elif event & eventloop.POLL_OUT: handle = True self._on_remote_write() @@ -1087,7 +1087,7 @@ class TCPRelayHandler(object): handle = True self._on_local_read() else: - self._recv_u_max_size = TCP_MSS + self._recv_u_max_size = self._tcp_mss - self._overhead elif event & eventloop.POLL_OUT: handle = True self._on_local_write()