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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,13 +912,13 @@ func (l *Listener) Accept() (net.Conn, error) {

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

select {
case <-timeout:
case <-l.timeout.C:
return nil, errors.WithStack(errTimeout)
case c := <-l.chAccepts:
return c, nil
Expand All @@ -939,6 +939,12 @@ func (l *Listener) SetDeadline(t time.Time) error {
// SetReadDeadline implements the Conn SetReadDeadline method.
func (l *Listener) SetReadDeadline(t time.Time) error {
l.rd.Store(t)

l.timeout.Stop()
if !t.IsZero() {
l.timeout.Reset(t.Sub(time.Now()))
}

return nil
}

Expand Down Expand Up @@ -1018,6 +1024,8 @@ func serveConn(block BlockCrypt, dataShards, parityShards int, conn net.PacketCo
l.parityShards = parityShards
l.block = block
l.chSocketReadError = make(chan struct{})
l.timeout = time.NewTimer(time.Hour) // get a paused timer, duration doesn't matter
l.timeout.Stop()
go l.monitor()
return l, nil
}
Expand Down