Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get file descriptor from NetConn for EPOLL handling? #497

Open
StarpTech opened this issue Oct 19, 2024 · 3 comments
Open

How to get file descriptor from NetConn for EPOLL handling? #497

StarpTech opened this issue Oct 19, 2024 · 3 comments

Comments

@StarpTech
Copy link

StarpTech commented Oct 19, 2024

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

@StarpTech
Copy link
Author

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
	}

@mafredri
Copy link
Member

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

@StarpTech
Copy link
Author

@mafredri thanks and that would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants