github.com/metacubex/mihomo@v1.18.5/transport/hysteria/core/stream.go (about)

     1  package core
     2  
     3  import (
     4  	"context"
     5  	"github.com/metacubex/quic-go"
     6  	"time"
     7  )
     8  
     9  // Handle stream close properly
    10  // Ref: https://github.com/libp2p/go-libp2p-quic-transport/blob/master/stream.go
    11  type wrappedQUICStream struct {
    12  	Stream quic.Stream
    13  }
    14  
    15  func (s *wrappedQUICStream) StreamID() quic.StreamID {
    16  	return s.Stream.StreamID()
    17  }
    18  
    19  func (s *wrappedQUICStream) Read(p []byte) (n int, err error) {
    20  	return s.Stream.Read(p)
    21  }
    22  
    23  func (s *wrappedQUICStream) CancelRead(code quic.StreamErrorCode) {
    24  	s.Stream.CancelRead(code)
    25  }
    26  
    27  func (s *wrappedQUICStream) SetReadDeadline(t time.Time) error {
    28  	return s.Stream.SetReadDeadline(t)
    29  }
    30  
    31  func (s *wrappedQUICStream) Write(p []byte) (n int, err error) {
    32  	return s.Stream.Write(p)
    33  }
    34  
    35  func (s *wrappedQUICStream) Close() error {
    36  	s.Stream.CancelRead(0)
    37  	return s.Stream.Close()
    38  }
    39  
    40  func (s *wrappedQUICStream) CancelWrite(code quic.StreamErrorCode) {
    41  	s.Stream.CancelWrite(code)
    42  }
    43  
    44  func (s *wrappedQUICStream) Context() context.Context {
    45  	return s.Stream.Context()
    46  }
    47  
    48  func (s *wrappedQUICStream) SetWriteDeadline(t time.Time) error {
    49  	return s.Stream.SetWriteDeadline(t)
    50  }
    51  
    52  func (s *wrappedQUICStream) SetDeadline(t time.Time) error {
    53  	return s.Stream.SetDeadline(t)
    54  }