v2ray-core/transport/internet/internal/sysfd.go

26 lines
486 B
Go
Raw Normal View History

2016-08-15 15:44:46 +00:00
package internal
import (
"net"
"reflect"
2016-12-04 08:10:47 +00:00
"v2ray.com/core/common/errors"
2016-08-15 15:44:46 +00:00
)
var (
ErrInvalidConn = errors.New("Invalid 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
}