mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 12:52:22 +08:00
Fix copy pipe
This commit is contained in:
parent
7e0958b4ac
commit
95c03c9373
|
@ -3,6 +3,7 @@ package outbound
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -136,22 +137,25 @@ func CopyEarlyConn(ctx context.Context, conn net.Conn, serverConn net.Conn) erro
|
||||||
_payload := buf.StackNew()
|
_payload := buf.StackNew()
|
||||||
payload := common.Dup(_payload)
|
payload := common.Dup(_payload)
|
||||||
err := conn.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout))
|
err := conn.SetReadDeadline(time.Now().Add(C.ReadPayloadTimeout))
|
||||||
if err != nil {
|
if err != os.ErrInvalid {
|
||||||
return err
|
if err != nil {
|
||||||
}
|
return err
|
||||||
_, err = payload.ReadOnceFrom(conn)
|
}
|
||||||
if err != nil && !E.IsTimeout(err) {
|
_, err = payload.ReadOnceFrom(conn)
|
||||||
return E.Cause(err, "read payload")
|
if err != nil && !E.IsTimeout(err) {
|
||||||
}
|
return E.Cause(err, "read payload")
|
||||||
err = conn.SetReadDeadline(time.Time{})
|
}
|
||||||
if err != nil {
|
err = conn.SetReadDeadline(time.Time{})
|
||||||
payload.Release()
|
if err != nil {
|
||||||
return err
|
payload.Release()
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_, err = serverConn.Write(payload.Bytes())
|
_, err = serverConn.Write(payload.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return N.HandshakeFailure(conn, err)
|
return N.HandshakeFailure(conn, err)
|
||||||
}
|
}
|
||||||
runtime.KeepAlive(_payload)
|
runtime.KeepAlive(_payload)
|
||||||
|
payload.Release()
|
||||||
return bufio.CopyConn(ctx, conn, serverConn)
|
return bufio.CopyConn(ctx, conn, serverConn)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user