mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
464 B
26 lines
464 B
8 years ago
|
package internal
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"net"
|
||
|
"reflect"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|