-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy patherror.go
More file actions
52 lines (42 loc) · 859 Bytes
/
error.go
File metadata and controls
52 lines (42 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
}
type wrapStreamCloseWrite struct {
*wrapStream
}
func newWrapStreamCloseWrite(conn net.Conn) *wrapStreamCloseWrite {
return &wrapStreamCloseWrite{wrapStream: &wrapStream{Conn: conn}}
}
func (w *wrapStreamCloseWrite) CloseWrite() error {
if c, ok := w.Conn.(interface{ CloseWrite() error }); ok {
return c.CloseWrite()
}
return nil
}
func wrapError(err error) error {
switch err {
case yamux.ErrStreamClosed:
return io.EOF
default:
return err
}
}