From c18a52bd74bddfc639968b96e4c2f2a2335c7565 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 4 Oct 2019 21:12:00 +0800 Subject: [PATCH] core: process refused TCP data immediately once the connection is ready If the first TCP data chunk was refused, perhaps due to the connection was under connecting state (it's almost always the case), waiting for timers to process the refused data would introduce a ~250ms (TCP_FAST_INTERVAL) delay for the connection. (from eycorsican/go-tun2socks) --- core/c/include/lwip/tcp.h | 2 ++ core/tcp_conn.go | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) mode change 100644 => 100755 core/c/include/lwip/tcp.h mode change 100644 => 100755 core/tcp_conn.go diff --git a/core/c/include/lwip/tcp.h b/core/c/include/lwip/tcp.h old mode 100644 new mode 100755 index 8c9ba98..24a7f12 --- a/core/c/include/lwip/tcp.h +++ b/core/c/include/lwip/tcp.h @@ -479,6 +479,8 @@ err_t tcp_output (struct tcp_pcb *pcb); err_t tcp_tcp_get_tcp_addrinfo(struct tcp_pcb *pcb, int local, ip_addr_t *addr, u16_t *port); +err_t tcp_process_refused_data(struct tcp_pcb *pcb); + #define tcp_dbg_get_tcp_state(pcb) ((pcb)->state) /* for compatibility with older implementation */ diff --git a/core/tcp_conn.go b/core/tcp_conn.go old mode 100644 new mode 100755 index 620f27d..6b87298 --- a/core/tcp_conn.go +++ b/core/tcp_conn.go @@ -64,7 +64,7 @@ type tcpConn struct { localAddr *net.TCPAddr connKeyArg unsafe.Pointer connKey uint32 - canWrite *sync.Cond // Condition variable to implement TCP back pressure. + canWrite *sync.Cond // Condition variable to implement TCP backpressure. state tcpConnState sndPipeReader *io.PipeReader sndPipeWriter *io.PipeWriter @@ -116,6 +116,12 @@ func newTCPConn(pcb *C.struct_tcp_pcb, handler TCPConnHandler) (TCPConn, error) conn.Lock() conn.state = tcpConnected conn.Unlock() + + lwipMutex.Lock() + if pcb.refused_data != nil { + C.tcp_process_refused_data(pcb) + } + lwipMutex.Unlock() } }() @@ -133,11 +139,9 @@ func (conn *tcpConn) LocalAddr() net.Addr { func (conn *tcpConn) SetDeadline(t time.Time) error { return nil } - func (conn *tcpConn) SetReadDeadline(t time.Time) error { return nil } - func (conn *tcpConn) SetWriteDeadline(t time.Time) error { return nil }