mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
feat: refine PacketConnectionReader
This commit is contained in:
parent
ca185b3310
commit
67c19f7054
@ -2,7 +2,6 @@ package trojan
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
core "github.com/v2fly/v2ray-core/v5"
|
||||
"github.com/v2fly/v2ray-core/v5/common"
|
||||
@ -120,12 +119,9 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
|
||||
defer timer.SetTimeout(sessionPolicy.Timeouts.UplinkOnly)
|
||||
|
||||
packetReader := &PacketReader{Reader: conn}
|
||||
splitReader := &PacketConnectionReader{
|
||||
readerAccess: &sync.Mutex{},
|
||||
reader: packetReader,
|
||||
}
|
||||
packetConnectionReader := &PacketConnectionReader{reader: packetReader}
|
||||
|
||||
return udp.CopyPacketConn(packetConn, splitReader, udp.UpdateActivity(timer))
|
||||
return udp.CopyPacketConn(packetConn, packetConnectionReader, udp.UpdateActivity(timer))
|
||||
}
|
||||
|
||||
responseDoneAndCloseWriter := task.OnSuccess(getResponse, task.Close(link.Writer))
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"encoding/binary"
|
||||
"io"
|
||||
gonet "net"
|
||||
"sync"
|
||||
|
||||
"github.com/v2fly/v2ray-core/v5/common/buf"
|
||||
"github.com/v2fly/v2ray-core/v5/common/net"
|
||||
@ -289,15 +288,11 @@ func (r *PacketReader) ReadMultiBufferWithMetadata() (*PacketPayload, error) {
|
||||
}
|
||||
|
||||
type PacketConnectionReader struct {
|
||||
readerAccess *sync.Mutex
|
||||
reader *PacketReader
|
||||
payload *PacketPayload
|
||||
reader *PacketReader
|
||||
payload *PacketPayload
|
||||
}
|
||||
|
||||
func (r *PacketConnectionReader) ReadFrom(p []byte) (n int, addr gonet.Addr, err error) {
|
||||
r.readerAccess.Lock()
|
||||
defer r.readerAccess.Unlock()
|
||||
|
||||
if r.payload == nil || r.payload.Buffer.IsEmpty() {
|
||||
r.payload, err = r.reader.ReadMultiBufferWithMetadata()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user