Browse Source

Respect mux.ErrReset (#113)

pull/1424/head
Hlib Kanunnikov 5 years ago
committed by GitHub
parent
commit
b8f591a4be
  1. 28
      p2p/transport/quic/stream.go

28
p2p/transport/quic/stream.go

@ -6,14 +6,36 @@ import (
quic "github.com/lucas-clemente/quic-go"
)
const (
reset quic.ErrorCode = 0
)
type stream struct {
quic.Stream
}
var _ mux.MuxedStream = &stream{}
func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.Stream.Read(b)
if serr, ok := err.(quic.StreamError); ok && serr.Canceled() {
err = mux.ErrReset
}
return n, err
}
func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.Stream.Write(b)
if serr, ok := err.(quic.StreamError); ok && serr.Canceled() {
err = mux.ErrReset
}
return n, err
}
func (s *stream) Reset() error {
s.Stream.CancelRead(0)
s.Stream.CancelWrite(0)
s.Stream.CancelRead(reset)
s.Stream.CancelWrite(reset)
return nil
}
var _ mux.MuxedStream = &stream{}

Loading…
Cancel
Save