mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
update fd logic for golang 1.9
This commit is contained in:
parent
c83a7b8311
commit
896bff2195
@ -1,25 +0,0 @@
|
||||
package internal
|
||||
|
||||
import (
|
||||
"net"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidConn = newError("not a net.Conn")
|
||||
)
|
||||
|
||||
// GetSysFd returns the underlying fd of a connection.
|
||||
func GetSysFd(conn net.Conn) (int, error) {
|
||||
cv := reflect.ValueOf(conn)
|
||||
switch ce := cv.Elem(); ce.Kind() {
|
||||
case reflect.Struct:
|
||||
netfd := ce.FieldByName("conn").FieldByName("fd")
|
||||
switch fe := netfd.Elem(); fe.Kind() {
|
||||
case reflect.Struct:
|
||||
fd := fe.FieldByName("sysfd")
|
||||
return int(fd.Int()), nil
|
||||
}
|
||||
}
|
||||
return 0, errInvalidConn
|
||||
}
|
@ -8,7 +8,6 @@ import (
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/dice"
|
||||
v2net "v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet/internal"
|
||||
)
|
||||
|
||||
// Payload represents a single UDP payload.
|
||||
@ -94,13 +93,17 @@ func ListenUDP(address v2net.Address, port v2net.Port, option ListenOption) (*Hu
|
||||
}
|
||||
log.Trace(newError("listening UDP on ", address, ":", port))
|
||||
if option.ReceiveOriginalDest {
|
||||
fd, err := internal.GetSysFd(udpConn)
|
||||
rawConn, err := udpConn.SyscallConn()
|
||||
if err != nil {
|
||||
return nil, newError("failed to get fd").Base(err)
|
||||
}
|
||||
err = SetOriginalDestOptions(fd)
|
||||
err = rawConn.Control(func(fd uintptr) {
|
||||
if err := SetOriginalDestOptions(int(fd)); err != nil {
|
||||
log.Trace(newError("failed to set socket options").Base(err))
|
||||
}
|
||||
})
|
||||
if err != nil {
|
||||
return nil, newError("failed to set socket options").Base(err)
|
||||
return nil, newError("failed to control socket").Base(err)
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
Loading…
Reference in New Issue
Block a user