Improve error processing

This commit is contained in:
世界
2022-07-30 09:57:02 +08:00
parent 9b9b5ebb72
commit d3378a575c
8 changed files with 38 additions and 8 deletions

View File

@@ -3,6 +3,7 @@ package mux
import (
"encoding/binary"
"io"
"net"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing/common"
@@ -117,3 +118,28 @@ func ReadResponse(reader io.Reader) (*Response, error) {
}
return &response, nil
}
type wrapStream struct {
net.Conn
}
func (w *wrapStream) Read(p []byte) (n int, err error) {
n, err = w.Conn.Read(p)
err = wrapError(err)
return
}
func (w *wrapStream) Write(p []byte) (n int, err error) {
n, err = w.Conn.Write(p)
err = wrapError(err)
return
}
func wrapError(err error) error {
switch err {
case yamux.ErrStreamClosed:
return io.EOF
default:
return err
}
}