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

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
}