1.4.5.2
This commit is contained in:
86
EdgeNode/internal/http3/stream.go
Normal file
86
EdgeNode/internal/http3/stream.go
Normal file
@@ -0,0 +1,86 @@
|
||||
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package http3
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/quic-go/quic-go"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Stream struct {
|
||||
rawStream quic.Stream
|
||||
|
||||
conn Conn
|
||||
}
|
||||
|
||||
func NewStream(rawStream quic.Stream, conn Conn) quic.Stream {
|
||||
return &Stream{
|
||||
rawStream: rawStream,
|
||||
conn: conn,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Stream) SetDeadline(t time.Time) error {
|
||||
return this.rawStream.SetDeadline(t)
|
||||
}
|
||||
|
||||
func (this *Stream) StreamID() quic.StreamID {
|
||||
return this.rawStream.StreamID()
|
||||
}
|
||||
|
||||
func (this *Stream) CancelRead(errorCode quic.StreamErrorCode) {
|
||||
this.rawStream.CancelRead(errorCode)
|
||||
}
|
||||
|
||||
func (this *Stream) SetReadDeadline(t time.Time) error {
|
||||
return this.rawStream.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (this *Stream) Read(p []byte) (n int, err error) {
|
||||
n, err = this.rawStream.Read(p)
|
||||
|
||||
// notify
|
||||
if n > 0 && this.conn != nil {
|
||||
var notifier = this.conn.notifier()
|
||||
if notifier != nil {
|
||||
notifier.ReadBytes(n)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Stream) CancelWrite(errorCode quic.StreamErrorCode) {
|
||||
this.rawStream.CancelWrite(errorCode)
|
||||
}
|
||||
|
||||
func (this *Stream) Context() context.Context {
|
||||
var ctx = this.rawStream.Context()
|
||||
if this.conn != nil {
|
||||
ctx = this.conn.callContextFunc(ctx)
|
||||
}
|
||||
return ctx
|
||||
}
|
||||
|
||||
func (this *Stream) SetWriteDeadline(t time.Time) error {
|
||||
return this.rawStream.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
func (this *Stream) Write(p []byte) (n int, err error) {
|
||||
n, err = this.rawStream.Write(p)
|
||||
|
||||
// notify
|
||||
if n > 0 && this.conn != nil {
|
||||
var notifier = this.conn.notifier()
|
||||
if notifier != nil {
|
||||
notifier.WriteBytes(n)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Stream) Close() error {
|
||||
return this.rawStream.Close()
|
||||
}
|
||||
Reference in New Issue
Block a user