mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-17 22:57:10 +00:00
update fd logic for golang 1.9
This commit is contained in:
1 parent
c83a7b8311
commit
896bff2195
2 files changed
+7
-29
No files matched your search
@@ -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())
|
||||
|
||||
Reference in new issue
Block a user