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)
This commit is contained in:
Jason
2019-10-04 21:12:00 +08:00
parent 934a8fb6af
commit c18a52bd74
2 changed files with 9 additions and 3 deletions

2
core/c/include/lwip/tcp.h Normal file → Executable file
View File

@@ -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 */

10
core/tcp_conn.go Normal file → Executable file
View File

@@ -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
}