Init commit

This commit is contained in:
世界 2023-04-23 17:05:39 +08:00
commit b8acf3f145
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
22 changed files with 2021 additions and 0 deletions

37
error.go Normal file
View file

@ -0,0 +1,37 @@
package mux
import (
"io"
"net"
"github.com/hashicorp/yamux"
)
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 (w *wrapStream) Upstream() any {
return w.Conn
}
func wrapError(err error) error {
switch err {
case yamux.ErrStreamClosed:
return io.EOF
default:
return err
}
}