github.com/sagernet/sing-mux@v0.2.1-0.20240124034317-9bfb33698bb6/error.go (about) 1 package mux 2 3 import ( 4 "io" 5 "net" 6 7 "github.com/hashicorp/yamux" 8 ) 9 10 type wrapStream struct { 11 net.Conn 12 } 13 14 func (w *wrapStream) Read(p []byte) (n int, err error) { 15 n, err = w.Conn.Read(p) 16 err = wrapError(err) 17 return 18 } 19 20 func (w *wrapStream) Write(p []byte) (n int, err error) { 21 n, err = w.Conn.Write(p) 22 err = wrapError(err) 23 return 24 } 25 26 func (w *wrapStream) Upstream() any { 27 return w.Conn 28 } 29 30 func wrapError(err error) error { 31 switch err { 32 case yamux.ErrStreamClosed: 33 return io.EOF 34 default: 35 return err 36 } 37 }