Skip to content

Commit

Permalink
fix: fix vet/staticcheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jul 15, 2021
1 parent eb4a589 commit 2f55bf5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
18 changes: 5 additions & 13 deletions multiplex.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ var ErrTwoInitiators = errors.New("two initiators")
var ErrInvalidState = errors.New("received an unexpected message from the peer")

var errTimeout = timeout{}
var errStreamClosed = errors.New("stream closed")

var (
ResetStreamTimeout = 2 * time.Minute
Expand All @@ -46,15 +45,15 @@ var (

type timeout struct{}

func (_ timeout) Error() string {
func (timeout) Error() string {
return "i/o deadline exceeded"
}

func (_ timeout) Temporary() bool {
func (timeout) Temporary() bool {
return true
}

func (_ timeout) Timeout() bool {
func (timeout) Timeout() bool {
return true
}

Expand Down Expand Up @@ -207,6 +206,7 @@ func (mp *Multiplex) handleOutgoing() {
}
}

//lint:ignore U1000 disabled
func (mp *Multiplex) writeMsg(data []byte) error {
if len(data) >= 512 {
err := mp.doWriteMsg(data)
Expand Down Expand Up @@ -526,7 +526,7 @@ func (mp *Multiplex) readNext() ([]byte, error) {
}

if l > uint64(MaxMessageSize) {
return nil, fmt.Errorf("message size too large!")
return nil, fmt.Errorf("message size too large")
}

if l == 0 {
Expand All @@ -541,11 +541,3 @@ func (mp *Multiplex) readNext() ([]byte, error) {

return buf[:n], nil
}

func isFatalNetworkError(err error) bool {
nerr, ok := err.(net.Error)
if ok {
return !(nerr.Timeout() || nerr.Temporary())
}
return false
}
21 changes: 15 additions & 6 deletions multiplex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,25 @@ func TestBasicStreams(t *testing.T) {
mpb := NewMultiplex(b, true)

mes := []byte("Hello world")
done := make(chan struct{})
go func() {
defer close(done)
s, err := mpb.Accept()
if err != nil {
t.Fatal(err)
t.Error(err)
}

_, err = s.Write(mes)
if err != nil {
t.Fatal(err)
t.Error(err)
}

err = s.Close()
if err != nil {
t.Fatal(err)
t.Error(err)
}
}()
defer func() { <-done }()

s, err := mpa.NewStream(context.Background())
if err != nil {
Expand Down Expand Up @@ -143,7 +146,7 @@ func TestWriteAfterClose(t *testing.T) {
go func() {
s, err := mpb.Accept()
if err != nil {
t.Fatal(err)
t.Error(err)
}

_, err = s.Write(mes)
Expand Down Expand Up @@ -198,7 +201,7 @@ func TestEcho(t *testing.T) {
go func() {
s, err := mpb.Accept()
if err != nil {
t.Fatal(err)
t.Error(err)
}

defer s.Close()
Expand Down Expand Up @@ -405,6 +408,9 @@ func TestReset(t *testing.T) {
t.Fatal(err)
}
sb, err := mpb.Accept()
if err != nil {
t.Fatal(err)
}

buf := make([]byte, 10)

Expand Down Expand Up @@ -635,6 +641,9 @@ func TestResetAfterEOF(t *testing.T) {
t.Fatal(err)
}
sb, err := mpb.Accept()
if err != nil {
t.Fatal(err)
}

if err := sa.CloseWrite(); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -764,7 +773,7 @@ func TestFuzzCloseStream(t *testing.T) {
var err error
streams[i], err = mpb.NewStream(context.Background())
if err != nil {
t.Fatal(err)
t.Error(err)
}

go streams[i].Close()
Expand Down

0 comments on commit 2f55bf5

Please sign in to comment.