-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
50 lines (44 loc) · 1.14 KB
/
utils.go
File metadata and controls
50 lines (44 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package asio
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())
}