Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shawwwn
Copy link

@shawwwn shawwwn commented Feb 8, 2021

kcp-go/sess.go

Lines 913 to 918 in 88fc14a

// AcceptKCP accepts a KCP connection
func (l *Listener) AcceptKCP() (*UDPSession, error) {
var timeout <-chan time.Time
if tdeadline, ok := l.rd.Load().(time.Time); ok && !tdeadline.IsZero() {
timeout = time.After(time.Until(tdeadline))
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant