Skip to content

Commit

Permalink
socketError stored with stack
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed May 10, 2019
1 parent be79ecb commit 2a54490
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions readloop_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package kcp

import (
"sync/atomic"

"github.com/pkg/errors"
)

func (s *UDPSession) readLoop() {
Expand All @@ -25,7 +27,7 @@ func (s *UDPSession) readLoop() {
atomic.AddUint64(&DefaultSnmp.InErrs, 1)
}
} else {
s.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
s.Close()
return
}
Expand All @@ -42,7 +44,7 @@ func (l *Listener) monitor() {
atomic.AddUint64(&DefaultSnmp.InErrs, 1)
}
} else {
l.socketError.Store(err)
l.socketError.Store(errors.WithStack(err))
l.Close()
return
}
Expand Down
5 changes: 3 additions & 2 deletions readloop_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"sync/atomic"

"github.com/pkg/errors"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
)
Expand Down Expand Up @@ -52,7 +53,7 @@ func (s *UDPSession) readLoop() {
s.packetInput(msg.Buffers[0][:msg.N])
}
} else {
s.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
s.Close()
return
}
Expand Down Expand Up @@ -85,7 +86,7 @@ func (l *Listener) monitor() {
}
}
} else {
l.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
l.Close()
return
}
Expand Down
4 changes: 2 additions & 2 deletions sess.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (s *UDPSession) Close() error {
s.l.closeSession(s.remote)
} else { // client socket close
if err := s.conn.Close(); err != nil {
s.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
}
}
close(s.die)
Expand Down Expand Up @@ -828,7 +828,7 @@ func (l *Listener) Close() (err error) {
var once bool
l.dieOnce.Do(func() {
if err := l.conn.Close(); err != nil {
l.socketError.Store(err)
l.socketError.Store(errors.WithStack(err))
}
close(l.die)
once = true
Expand Down
6 changes: 4 additions & 2 deletions tx_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package kcp

import (
"sync/atomic"

"github.com/pkg/errors"
)

func (s *UDPSession) txLoop() {
Expand All @@ -16,7 +18,7 @@ func (s *UDPSession) txLoop() {
nbytes += n
xmitBuf.Put(txqueue[k].Buffers[0])
} else {
s.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
s.Close()
return
}
Expand All @@ -39,7 +41,7 @@ func (l *Listener) txLoop() {
nbytes += n
xmitBuf.Put(txqueue[k].Buffers[0])
} else {
l.socketError.Store(err)
l.socketError.Store(errors.WithStack(err))
l.Close()
return
}
Expand Down
5 changes: 3 additions & 2 deletions tx_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net"
"sync/atomic"

"github.com/pkg/errors"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
)
Expand All @@ -30,7 +31,7 @@ func (s *UDPSession) txLoop() {
if n, err := conn.WriteBatch(vec, 0); err == nil {
vec = vec[n:]
} else {
s.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
s.Close()
return
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func (l *Listener) txLoop() {
if n, err := conn.WriteBatch(vec, 0); err == nil {
vec = vec[n:]
} else {
l.socketError.Store(err)
s.socketError.Store(errors.WithStack(err))
l.Close()
return
}
Expand Down

0 comments on commit 2a54490

Please sign in to comment.