How to get file descriptor from NetConn for EPOLL handling?
Hi, as titled. We are trying to get the raw TCP connection to read the file descriptor.
netConn := websocket.NetConn(reqCtx.Context(), wsConn, websocket.MessageText)
We want to use this library in combination with https://github.com/smallnest/epoller
Our workaround
var netConn net.Conn
clientTrace := &httptrace.ClientTrace{
GotConn: func(info httptrace.GotConnInfo) {
netConn = info.Conn
},
}
clientTraceCtx := httptrace.WithClientTrace(requestContext, clientTrace)
conn, upgradeResponse, err := websocket.Dial(clientTraceCtx, options.URL, &websocket.DialOptions{
HTTPClient: c.httpClient,
HTTPHeader: options.Header,
CompressionMode: websocket.CompressionDisabled,
Subprotocols: subProtocols,
})
if err != nil {
return nil, err
}
Thanks for sharing your workaround @StarpTech! We'll think about the API but surely we can expose an easier way to grab the raw net.Conn.
Somewhat related: #331
@mafredri thanks and that would be great!
Thanks for sharing the workaround @StarpTech, needed the Conn for something else and this made the trick.
Did you manage to use epoller with the library in the end? I'm curious to learn if it works and roughly how it improve things.