ceremonyclient/go-libp2p/p2p/muxer/mplex/stream.go

65 lines
1.1 KiB
Go
Raw Normal View History

2023-08-21 03:50:38 +00:00
package mplex
import (
"time"
"github.com/libp2p/go-libp2p/core/network"
mp "github.com/libp2p/go-mplex"
)
// stream implements network.MuxedStream over mplex.Stream.
type stream mp.Stream
var _ network.MuxedStream = &stream{}
func (s *stream) Read(b []byte) (n int, err error) {
n, err = s.mplex().Read(b)
if err == mp.ErrStreamReset {
err = network.ErrReset
}
return n, err
}
func (s *stream) Write(b []byte) (n int, err error) {
n, err = s.mplex().Write(b)
if err == mp.ErrStreamReset {
err = network.ErrReset
}
return n, err
}
func (s *stream) Close() error {
return s.mplex().Close()
}
func (s *stream) CloseWrite() error {
return s.mplex().CloseWrite()
}
func (s *stream) CloseRead() error {
return s.mplex().CloseRead()
}
func (s *stream) Reset() error {
return s.mplex().Reset()
}
func (s *stream) SetDeadline(t time.Time) error {
return s.mplex().SetDeadline(t)
}
func (s *stream) SetReadDeadline(t time.Time) error {
return s.mplex().SetReadDeadline(t)
}
func (s *stream) SetWriteDeadline(t time.Time) error {
return s.mplex().SetWriteDeadline(t)
}
func (s *stream) mplex() *mp.Stream {
return (*mp.Stream)(s)
}