fix: tuic stream close
This commit is contained in:
parent
9976800a35
commit
9b1fe9f466
1 changed files with 9 additions and 3 deletions
|
@ -209,7 +209,7 @@ func (t *Client) deferQuicConn(quicConn quic.Connection, err error) {
|
||||||
func (t *Client) Close(err error) {
|
func (t *Client) Close(err error) {
|
||||||
quicConn := t.quicConn
|
quicConn := t.quicConn
|
||||||
if quicConn != nil {
|
if quicConn != nil {
|
||||||
_ = t.quicConn.CloseWithError(ProtocolError, err.Error())
|
_ = quicConn.CloseWithError(ProtocolError, err.Error())
|
||||||
t.udpInputMap.Range(func(key, value any) bool {
|
t.udpInputMap.Range(func(key, value any) bool {
|
||||||
if conn, ok := value.(net.Conn); ok {
|
if conn, ok := value.(net.Conn); ok {
|
||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
|
@ -256,14 +256,15 @@ func (t *Client) DialContext(ctx context.Context, metadata *C.Metadata, dialFn f
|
||||||
conn := N.NewBufferedConn(&quicStreamConn{stream, quicConn.LocalAddr(), quicConn.RemoteAddr(), t})
|
conn := N.NewBufferedConn(&quicStreamConn{stream, quicConn.LocalAddr(), quicConn.RemoteAddr(), t})
|
||||||
response, err := ReadResponse(conn)
|
response, err := ReadResponse(conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = conn.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if response.IsFailed() {
|
if response.IsFailed() {
|
||||||
_ = stream.Close()
|
_ = conn.Close()
|
||||||
return nil, errors.New("connect failed")
|
return nil, errors.New("connect failed")
|
||||||
}
|
}
|
||||||
_ = stream.SetReadDeadline(time.Time{})
|
_ = stream.SetReadDeadline(time.Time{})
|
||||||
return conn, err
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type quicStreamConn struct {
|
type quicStreamConn struct {
|
||||||
|
@ -273,6 +274,11 @@ type quicStreamConn struct {
|
||||||
client *Client
|
client *Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (q *quicStreamConn) Close() error {
|
||||||
|
q.Stream.CancelRead(0)
|
||||||
|
return q.Stream.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (q *quicStreamConn) LocalAddr() net.Addr {
|
func (q *quicStreamConn) LocalAddr() net.Addr {
|
||||||
return q.lAddr
|
return q.lAddr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue