mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-24 22:26:05 +03:00
Revert "Fix freedom PacketReader/PacketWriter type assertion (#3734)"
This reverts commit 815a959c96
.
This commit is contained in:
parent
6baad79f98
commit
f1c439c2aa
@ -286,24 +286,24 @@ func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
|
|||||||
if statConn != nil {
|
if statConn != nil {
|
||||||
counter = statConn.ReadCounter
|
counter = statConn.ReadCounter
|
||||||
}
|
}
|
||||||
if c, ok := iConn.(net.PacketConn); ok && UDPOverride.Address == nil && UDPOverride.Port == 0 {
|
if c, ok := iConn.(*internet.PacketConnWrapper); ok && UDPOverride.Address == nil && UDPOverride.Port == 0 {
|
||||||
return &PacketReader{
|
return &PacketReader{
|
||||||
PacketConn: c,
|
PacketConnWrapper: c,
|
||||||
Counter: counter,
|
Counter: counter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &buf.PacketReader{Reader: conn}
|
return &buf.PacketReader{Reader: conn}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PacketReader struct {
|
type PacketReader struct {
|
||||||
net.PacketConn
|
*internet.PacketConnWrapper
|
||||||
stats.Counter
|
stats.Counter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
||||||
b := buf.New()
|
b := buf.New()
|
||||||
b.Resize(0, buf.Size)
|
b.Resize(0, buf.Size)
|
||||||
n, d, err := r.PacketConn.ReadFrom(b.Bytes())
|
n, d, err := r.PacketConnWrapper.ReadFrom(b.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.Release()
|
b.Release()
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -330,14 +330,13 @@ func NewPacketWriter(conn net.Conn, h *Handler, ctx context.Context, UDPOverride
|
|||||||
if statConn != nil {
|
if statConn != nil {
|
||||||
counter = statConn.WriteCounter
|
counter = statConn.WriteCounter
|
||||||
}
|
}
|
||||||
if c, ok := iConn.(net.PacketConn); ok {
|
if c, ok := iConn.(*internet.PacketConnWrapper); ok {
|
||||||
return &PacketWriter{
|
return &PacketWriter{
|
||||||
PacketConn: c,
|
PacketConnWrapper: c,
|
||||||
Counter: counter,
|
Counter: counter,
|
||||||
Handler: h,
|
Handler: h,
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
UDPOverride: UDPOverride,
|
UDPOverride: UDPOverride,
|
||||||
Conn: iConn,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -345,12 +344,11 @@ func NewPacketWriter(conn net.Conn, h *Handler, ctx context.Context, UDPOverride
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PacketWriter struct {
|
type PacketWriter struct {
|
||||||
net.PacketConn
|
*internet.PacketConnWrapper
|
||||||
stats.Counter
|
stats.Counter
|
||||||
*Handler
|
*Handler
|
||||||
context.Context
|
context.Context
|
||||||
UDPOverride net.Destination
|
UDPOverride net.Destination
|
||||||
Conn net.Conn
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||||
@ -380,9 +378,9 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|||||||
b.Release()
|
b.Release()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
n, err = w.PacketConn.WriteTo(b.Bytes(), destAddr)
|
n, err = w.PacketConnWrapper.WriteTo(b.Bytes(), destAddr)
|
||||||
} else {
|
} else {
|
||||||
n, err = w.Conn.Write(b.Bytes())
|
n, err = w.PacketConnWrapper.Write(b.Bytes())
|
||||||
}
|
}
|
||||||
b.Release()
|
b.Release()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user