stream.go 732 B

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