Can't get fd from tls.Conn

Viewed 491

Is there any way to get the file descriptor from a tls.Conn?

I'm trying to add tls to epoll. But I can't find fd in a tls.Conn.

1 Answers
 func FDFromTLSConn(conn tls.Conn) int {
    tcpConn := reflect.Indirect(reflect.ValueOf(conn)).FieldByName("conn")
    fdVal := tcpConn.FieldByName("fd")
    pfdVal := reflect.Indirect(fdVal).FieldByName("pfd")

    return int(pfdVal.FieldByName("Sysfd").Int())
   }
Related