github.com/sagernet/sing-box@v1.9.0-rc.20/transport/v2rayquic/stream.go (about) 1 package v2rayquic 2 3 import ( 4 "net" 5 6 "github.com/sagernet/quic-go" 7 "github.com/sagernet/sing/common/baderror" 8 ) 9 10 type StreamWrapper struct { 11 Conn quic.Connection 12 quic.Stream 13 } 14 15 func (s *StreamWrapper) Read(p []byte) (n int, err error) { 16 n, err = s.Stream.Read(p) 17 return n, baderror.WrapQUIC(err) 18 } 19 20 func (s *StreamWrapper) Write(p []byte) (n int, err error) { 21 n, err = s.Stream.Write(p) 22 return n, baderror.WrapQUIC(err) 23 } 24 25 func (s *StreamWrapper) LocalAddr() net.Addr { 26 return s.Conn.LocalAddr() 27 } 28 29 func (s *StreamWrapper) RemoteAddr() net.Addr { 30 return s.Conn.RemoteAddr() 31 } 32 33 func (s *StreamWrapper) Upstream() any { 34 return s.Stream 35 } 36 37 func (s *StreamWrapper) Close() error { 38 s.CancelRead(0) 39 s.Stream.Close() 40 return nil 41 }