Fix close pipe

This commit is contained in:
世界 2022-05-30 19:45:20 +08:00
parent f0b58d9ee0
commit 91ce752405
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
4 changed files with 17 additions and 30 deletions

View file

@ -67,9 +67,6 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
if outbound == nil || !outbound.Target.IsValid() {
return newError("target not specified")
}
/*if statConn, ok := inboundConn.(*internet.StatCounterConn); ok {
inboundConn = statConn.Connection
}*/
destination := outbound.Target
network := destination.Network
@ -92,6 +89,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
}
_payload := B.StackNew()
payload := C.Dup(_payload)
defer payload.Release()
for {
payload.FullReset()
nb, n := buf.SplitBytes(mb, payload.FreeBytes())
@ -127,7 +125,7 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
conn.R = &buf.BufferedReader{Reader: link.Reader}
}
return bufio.CopyConn(ctx, conn, serverConn)
return returnError(bufio.CopyConn(ctx, conn, serverConn))
} else {
var packetConn N.PacketConn
if pc, isPacketConn := inboundConn.(N.PacketConn); isPacketConn {
@ -144,6 +142,6 @@ func (o *Outbound) Process(ctx context.Context, link *transport.Link, dialer int
}
serverConn := o.method.DialPacketConn(connection)
return bufio.CopyPacketConn(ctx, packetConn, serverConn)
return returnError(bufio.CopyPacketConn(ctx, packetConn, serverConn))
}
}

View file

@ -1,11 +1,11 @@
package shadowsocks_2022
import (
"errors"
"io"
B "github.com/sagernet/sing/common/buf"
M "github.com/sagernet/sing/common/metadata"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
)
@ -47,9 +47,6 @@ type pipeConnWrapper struct {
}
func (w *pipeConnWrapper) Close() error {
common.Interrupt(w.R)
common.Interrupt(w.W)
common.Close(w.Conn)
return nil
}
@ -136,8 +133,13 @@ func (w *packetConnWrapper) WritePacket(buffer *B.Buffer, destination M.Socksadd
}
func (w *packetConnWrapper) Close() error {
common.Interrupt(w.Reader)
common.Close(w.Conn)
buf.ReleaseMulti(w.cached)
return nil
}
func returnError(err error) error {
if errors.Is(err, io.EOF) {
return nil
}
return err
}