mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 17:46:58 -05:00
change ToPacketAddrConnWrapper to fused connection
This commit is contained in:
parent
409c4e9c98
commit
5b536a7d02
@ -2,7 +2,6 @@ package packetaddr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
|
||||||
gonet "net"
|
gonet "net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -107,18 +106,27 @@ func (c packetConnectionAdaptor) SetWriteDeadline(t time.Time) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToPacketAddrReadWriteCloser(conn net.PacketConn, isStream bool) io.ReadWriteCloser {
|
func ToPacketAddrConnWrapper(conn net.PacketConn, isStream bool) FusedConnection {
|
||||||
return &packetConnWrapper{conn}
|
return &packetConnWrapper{conn}
|
||||||
}
|
}
|
||||||
|
|
||||||
type packetConnWrapper struct {
|
type packetConnWrapper struct {
|
||||||
conn net.PacketConn
|
net.PacketConn
|
||||||
|
}
|
||||||
|
|
||||||
|
func (pc *packetConnWrapper) RemoteAddr() gonet.Addr {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type FusedConnection interface {
|
||||||
|
net.PacketConn
|
||||||
|
net.Conn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *packetConnWrapper) Read(p []byte) (n int, err error) {
|
func (pc *packetConnWrapper) Read(p []byte) (n int, err error) {
|
||||||
recbuf := buf.StackNew()
|
recbuf := buf.StackNew()
|
||||||
recbuf.Extend(2048)
|
recbuf.Extend(2048)
|
||||||
n, addr, err := pc.conn.ReadFrom(recbuf.Bytes())
|
n, addr, err := pc.PacketConn.ReadFrom(recbuf.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
@ -129,7 +137,7 @@ func (pc *packetConnWrapper) Read(p []byte) (n int, err error) {
|
|||||||
|
|
||||||
func (pc *packetConnWrapper) Write(p []byte) (n int, err error) {
|
func (pc *packetConnWrapper) Write(p []byte) (n int, err error) {
|
||||||
data, addr := ExtractAddressFromPacket(p)
|
data, addr := ExtractAddressFromPacket(p)
|
||||||
_, err = pc.conn.WriteTo(data, addr)
|
_, err = pc.PacketConn.WriteTo(data, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user