|
|
|
@ -276,9 +276,9 @@ func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
|
|
|
|
|
if statConn != nil { |
|
|
|
|
counter = statConn.ReadCounter |
|
|
|
|
} |
|
|
|
|
if c, ok := iConn.(*internet.PacketConnWrapper); ok && UDPOverride.Address == nil && UDPOverride.Port == 0 { |
|
|
|
|
if c, ok := iConn.(net.PacketConn); ok && UDPOverride.Address == nil && UDPOverride.Port == 0 { |
|
|
|
|
return &PacketReader{ |
|
|
|
|
PacketConnWrapper: c, |
|
|
|
|
PacketConn: c, |
|
|
|
|
Counter: counter, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -286,14 +286,14 @@ func NewPacketReader(conn net.Conn, UDPOverride net.Destination) buf.Reader {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type PacketReader struct { |
|
|
|
|
*internet.PacketConnWrapper |
|
|
|
|
net.PacketConn |
|
|
|
|
stats.Counter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) { |
|
|
|
|
b := buf.New() |
|
|
|
|
b.Resize(0, buf.Size) |
|
|
|
|
n, d, err := r.PacketConnWrapper.ReadFrom(b.Bytes()) |
|
|
|
|
n, d, err := r.PacketConn.ReadFrom(b.Bytes()) |
|
|
|
|
if err != nil { |
|
|
|
|
b.Release() |
|
|
|
|
return nil, err |
|
|
|
@ -320,24 +320,26 @@ func NewPacketWriter(conn net.Conn, h *Handler, ctx context.Context, UDPOverride
|
|
|
|
|
if statConn != nil { |
|
|
|
|
counter = statConn.WriteCounter |
|
|
|
|
} |
|
|
|
|
if c, ok := iConn.(*internet.PacketConnWrapper); ok { |
|
|
|
|
if c, ok := iConn.(net.PacketConn); ok { |
|
|
|
|
return &PacketWriter{ |
|
|
|
|
PacketConnWrapper: c, |
|
|
|
|
PacketConn: c, |
|
|
|
|
Counter: counter, |
|
|
|
|
Handler: h, |
|
|
|
|
Context: ctx, |
|
|
|
|
UDPOverride: UDPOverride, |
|
|
|
|
Conn: iConn, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return &buf.SequentialWriter{Writer: conn} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type PacketWriter struct { |
|
|
|
|
*internet.PacketConnWrapper |
|
|
|
|
net.PacketConn |
|
|
|
|
stats.Counter |
|
|
|
|
*Handler |
|
|
|
|
context.Context |
|
|
|
|
UDPOverride net.Destination |
|
|
|
|
Conn net.Conn |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { |
|
|
|
@ -367,9 +369,9 @@ func (w *PacketWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
|
|
|
|
b.Release() |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
n, err = w.PacketConnWrapper.WriteTo(b.Bytes(), destAddr) |
|
|
|
|
n, err = w.PacketConn.WriteTo(b.Bytes(), destAddr) |
|
|
|
|
} else { |
|
|
|
|
n, err = w.PacketConnWrapper.Write(b.Bytes()) |
|
|
|
|
n, err = w.Conn.Write(b.Bytes()) |
|
|
|
|
} |
|
|
|
|
b.Release() |
|
|
|
|
if err != nil { |
|
|
|
|