mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-09 18:43:14 +00:00
Fix QUIC stream usage
This commit is contained in:
parent
6b943caf37
commit
806f7d0a2b
|
@ -5,7 +5,6 @@ import (
|
|||
"crypto/tls"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
@ -184,8 +183,8 @@ func (c *Client) DialConn(ctx context.Context, destination M.Socksaddr) (net.Con
|
|||
return nil, err
|
||||
}
|
||||
return &clientConn{
|
||||
Stream: stream,
|
||||
parent: conn,
|
||||
stream: stream,
|
||||
destination: destination,
|
||||
}, nil
|
||||
}
|
||||
|
@ -253,8 +252,8 @@ func (c *clientQUICConnection) closeWithError(err error) {
|
|||
}
|
||||
|
||||
type clientConn struct {
|
||||
quic.Stream
|
||||
parent *clientQUICConnection
|
||||
stream quic.Stream
|
||||
destination M.Socksaddr
|
||||
requestWritten bool
|
||||
}
|
||||
|
@ -264,7 +263,7 @@ func (c *clientConn) NeedHandshake() bool {
|
|||
}
|
||||
|
||||
func (c *clientConn) Read(b []byte) (n int, err error) {
|
||||
n, err = c.stream.Read(b)
|
||||
n, err = c.Stream.Read(b)
|
||||
return n, baderror.WrapQUIC(err)
|
||||
}
|
||||
|
||||
|
@ -279,7 +278,7 @@ func (c *clientConn) Write(b []byte) (n int, err error) {
|
|||
return
|
||||
}
|
||||
request.Write(b)
|
||||
_, err = c.stream.Write(request.Bytes())
|
||||
_, err = c.Stream.Write(request.Bytes())
|
||||
if err != nil {
|
||||
c.parent.closeWithError(E.Cause(err, "create new connection"))
|
||||
return 0, baderror.WrapQUIC(err)
|
||||
|
@ -287,17 +286,13 @@ func (c *clientConn) Write(b []byte) (n int, err error) {
|
|||
c.requestWritten = true
|
||||
return len(b), nil
|
||||
}
|
||||
n, err = c.stream.Write(b)
|
||||
n, err = c.Stream.Write(b)
|
||||
return n, baderror.WrapQUIC(err)
|
||||
}
|
||||
|
||||
func (c *clientConn) Close() error {
|
||||
stream := c.stream
|
||||
if stream == nil {
|
||||
return nil
|
||||
}
|
||||
stream.CancelRead(0)
|
||||
return stream.Close()
|
||||
c.Stream.CancelRead(0)
|
||||
return c.Stream.Close()
|
||||
}
|
||||
|
||||
func (c *clientConn) LocalAddr() net.Addr {
|
||||
|
@ -307,24 +302,3 @@ func (c *clientConn) LocalAddr() net.Addr {
|
|||
func (c *clientConn) RemoteAddr() net.Addr {
|
||||
return c.destination
|
||||
}
|
||||
|
||||
func (c *clientConn) SetDeadline(t time.Time) error {
|
||||
if c.stream == nil {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
return c.stream.SetDeadline(t)
|
||||
}
|
||||
|
||||
func (c *clientConn) SetReadDeadline(t time.Time) error {
|
||||
if c.stream == nil {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
return c.stream.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (c *clientConn) SetWriteDeadline(t time.Time) error {
|
||||
if c.stream == nil {
|
||||
return os.ErrInvalid
|
||||
}
|
||||
return c.stream.SetWriteDeadline(t)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue