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