Skip to content

Commit

Permalink
expose errors definition in smux
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Sep 22, 2019
1 parent 6bc2f14 commit 0e3229b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const (
)

var (
errInvalidProtocol = errors.New("invalid protocol")
errGoAway = errors.New("stream id overflows, should start a new connection")
errTimeout = errors.New("timeout")
ErrInvalidProtocol = errors.New("invalid protocol")
ErrGoAway = errors.New("stream id overflows, should start a new connection")
ErrTimeout = errors.New("timeout")
)

type writeRequest struct {
Expand Down Expand Up @@ -117,15 +117,15 @@ func (s *Session) OpenStream() (*Stream, error) {
s.nextStreamIDLock.Lock()
if s.goAway > 0 {
s.nextStreamIDLock.Unlock()
return nil, errors.WithStack(errGoAway)
return nil, errors.WithStack(ErrGoAway)
}

s.nextStreamID += 2
sid := s.nextStreamID
if sid == sid%2 { // stream-id overflows
s.goAway = 1
s.nextStreamIDLock.Unlock()
return nil, errors.WithStack(errGoAway)
return nil, errors.WithStack(ErrGoAway)
}
s.nextStreamIDLock.Unlock()

Expand Down Expand Up @@ -167,7 +167,7 @@ func (s *Session) AcceptStream() (*Stream, error) {
case stream := <-s.chAccepts:
return stream, nil
case <-deadline:
return nil, errors.WithStack(errTimeout)
return nil, errors.WithStack(ErrTimeout)
case <-s.chSocketReadError:
return nil, s.socketReadError.Load().(error)
case <-s.chProtoError:
Expand Down Expand Up @@ -314,7 +314,7 @@ func (s *Session) recvLoop() {
if _, err := io.ReadFull(s.conn, hdr[:]); err == nil {
atomic.StoreInt32(&s.dataReady, 1)
if hdr.Version() != version {
s.notifyProtoError(errors.WithStack(errInvalidProtocol))
s.notifyProtoError(errors.WithStack(ErrInvalidProtocol))
return
}
sid := hdr.StreamID()
Expand Down Expand Up @@ -355,7 +355,7 @@ func (s *Session) recvLoop() {
}
}
default:
s.notifyProtoError(errors.WithStack(errInvalidProtocol))
s.notifyProtoError(errors.WithStack(ErrInvalidProtocol))
return
}
} else {
Expand Down Expand Up @@ -488,7 +488,7 @@ func (s *Session) writeFrameInternal(f Frame, deadline <-chan time.Time, prio ui
case <-s.chSocketWriteError:
return 0, s.socketWriteError.Load().(error)
case <-deadline:
return 0, errors.WithStack(errTimeout)
return 0, errors.WithStack(ErrTimeout)
}

select {
Expand All @@ -499,6 +499,6 @@ func (s *Session) writeFrameInternal(f Frame, deadline <-chan time.Time, prio ui
case <-s.chSocketWriteError:
return 0, s.socketWriteError.Load().(error)
case <-deadline:
return 0, errors.WithStack(errTimeout)
return 0, errors.WithStack(ErrTimeout)
}
}
2 changes: 1 addition & 1 deletion stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *Stream) Read(b []byte) (n int, err error) {
case <-s.sess.chProtoError:
return 0, s.sess.protoError.Load().(error)
case <-deadline:
return n, errors.WithStack(errTimeout)
return n, errors.WithStack(ErrTimeout)
case <-s.die:
return 0, errors.WithStack(io.ErrClosedPipe)
}
Expand Down

0 comments on commit 0e3229b

Please sign in to comment.