xtaci / kcp-go

A Crypto-Secure Reliable-UDP Library for golang with FEC
MIT License
4.12k stars 737 forks source link

fix SetReadDeadline() has no effect after AcceptKCP() has been called #193

Open shawwwn opened 3 years ago

shawwwn commented 3 years ago

https://github.com/xtaci/kcp-go/blob/88fc14ae6dc5ff6eed704407e5f72ff0d28a7013/sess.go#L913-L918

Here var timeout is fixed, thus subsequent calls to SetDeadline() after AcceptKCP() will not be able to change the listener's timeout.

lis.SetDeadline(time.Now().Add(10 * time.Second))       // OK
conn, _ := lis.AcceptKCP()

go func() {
    <-time.After(5 * time.Second)
    lis.SetDeadline(time.Now().Add(10 * time.Second))   // Has no effect
}()

From a naive understanding of the go document, calling SetReadDeadline() should be able to extend the deadline of the underlying connection. https://golang.org/pkg/net/#PacketConn