status-go/vendor/github.com/libp2p/go-libp2p/p2p/muxer/yamux/stream.go

65 lines
1.1 KiB
Go
Raw Normal View History

package yamux
import (
"time"
2022-11-04 13:57:20 +00:00
"github.com/libp2p/go-libp2p/core/network"
2022-04-01 16:16:46 +00:00
2022-11-04 13:57:20 +00:00
"github.com/libp2p/go-yamux/v4"
)
// stream implements mux.MuxedStream over yamux.Stream.
type stream yamux.Stream
2022-04-01 16:16:46 +00:00
var _ network.MuxedStream = &stream{}
func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.yamux().Read(b)
if err == yamux.ErrStreamReset {
2022-04-01 16:16:46 +00:00
err = network.ErrReset
}
return n, err
}
func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.yamux().Write(b)
if err == yamux.ErrStreamReset {
2022-04-01 16:16:46 +00:00
err = network.ErrReset
}
return n, err
}
func (s *stream) Close() error {
return s.yamux().Close()
}
func (s *stream) Reset() error {
return s.yamux().Reset()
}
func (s *stream) CloseRead() error {
return s.yamux().CloseRead()
}
func (s *stream) CloseWrite() error {
return s.yamux().CloseWrite()
}
func (s *stream) SetDeadline(t time.Time) error {
return s.yamux().SetDeadline(t)
}
func (s *stream) SetReadDeadline(t time.Time) error {
return s.yamux().SetReadDeadline(t)
}
func (s *stream) SetWriteDeadline(t time.Time) error {
return s.yamux().SetWriteDeadline(t)
}
func (s *stream) yamux() *yamux.Stream {
return (*yamux.Stream)(s)
}