1 Star 0 Fork 0

王布衣/asio

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.go 1.15 KB
一键复制 编辑 原始数据 按行查看 历史
package backup
import (
"errors"
"net"
"os"
"reflect"
)
// filer describes an object that has ability to return os.File.
type filer interface {
// File returns a copy of object's file descriptor.
File() (*os.File, error)
}
func handle(x interface{}) (socket_t, error) {
f, ok := x.(filer)
if !ok {
return -1, errors.New("not filter")
}
// Get a copy of fd.
file, err := f.File()
if err != nil {
return -1, err
}
return int(file.Fd()), nil
}
func handle3(conn net.Conn) (socket_t, error) {
tcpConn := conn.(*net.TCPConn)
file, err := tcpConn.File()
if err != nil {
return -1, err
}
return int(file.Fd()), nil
}
func socketFD(conn net.Conn) int {
//tls := reflect.TypeOf(conn.UnderlyingConn()) == reflect.TypeOf(&tls.Conn{})
// Extract the file descriptor associated with the connection
//connVal := reflect.Indirect(reflect.ValueOf(conn)).FieldByName("conn").Elem()
tcpConn := reflect.Indirect(reflect.ValueOf(conn)).FieldByName("conn")
//if tls {
// tcpConn = reflect.Indirect(tcpConn.Elem())
//}
fdVal := tcpConn.FieldByName("fd")
pfdVal := reflect.Indirect(fdVal).FieldByName("pfd")
return int(pfdVal.FieldByName("Sysfd").Int())
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/asio.git
git@gitee.com:quant1x/asio.git
quant1x
asio
asio
v1.1.5

搜索帮助