1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-17 09:56:18 -05:00
v2fly/transport/internet/internal/sysfd.go

28 lines
542 B
Go
Raw Normal View History

2016-08-15 11:44:46 -04:00
package internal
import (
"net"
"reflect"
2017-01-01 16:12:44 -05:00
2016-12-04 03:10:47 -05:00
"v2ray.com/core/common/errors"
2016-08-15 11:44:46 -04:00
)
var (
2017-01-01 16:12:44 -05:00
errInvalidConn = errors.New("Invalid Connection.")
2016-08-15 11:44:46 -04:00
)
2017-01-01 16:12:44 -05:00
// GetSysFd returns the underlying fd of a connection.
2016-08-15 11:44:46 -04:00
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
}
}
2017-01-01 16:12:44 -05:00
return 0, errInvalidConn
2016-08-15 11:44:46 -04:00
}