Skip to content

Commit

Permalink
Merge pull request #815 from Wondertan/fix/reset-error
Browse files Browse the repository at this point in the history
Use of mux.ErrReset in mocknet
  • Loading branch information
Stebalien committed Mar 7, 2020
2 parents 5a6c36d + 5e30cde commit ebb9cb8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions p2p/net/mock/mock_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync/atomic"
"time"

"github.com/libp2p/go-libp2p-core/mux"
"github.com/libp2p/go-libp2p-core/network"
protocol "github.com/libp2p/go-libp2p-core/protocol"
)
Expand All @@ -29,7 +30,6 @@ type stream struct {
stat network.Stat
}

var ErrReset error = errors.New("stream reset")
var ErrClosed error = errors.New("stream closed")

type transportObject struct {
Expand Down Expand Up @@ -98,8 +98,8 @@ func (s *stream) Close() error {

func (s *stream) Reset() error {
// Cancel any pending reads/writes with an error.
s.write.CloseWithError(ErrReset)
s.read.CloseWithError(ErrReset)
s.write.CloseWithError(mux.ErrReset)
s.read.CloseWithError(mux.ErrReset)

select {
case s.reset <- struct{}{}:
Expand Down Expand Up @@ -206,7 +206,7 @@ func (s *stream) transport() {
case s.reset <- struct{}{}:
default:
}
return ErrReset
return mux.ErrReset
}
if err := drainBuf(); err != nil {
return err
Expand All @@ -226,14 +226,14 @@ func (s *stream) transport() {
// Reset takes precedent.
select {
case <-s.reset:
s.writeErr = ErrReset
s.writeErr = mux.ErrReset
return
default:
}

select {
case <-s.reset:
s.writeErr = ErrReset
s.writeErr = mux.ErrReset
return
case <-s.close:
if err := drainBuf(); err != nil {
Expand Down

0 comments on commit ebb9cb8

Please sign in to comment.