Skip to content

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

Open
@StarpTech

Description

@StarpTech

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

Activity

StarpTech

StarpTech commented on Oct 20, 2024

@StarpTech
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

mafredri commented on Nov 14, 2024

@mafredri
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

StarpTech commented on Nov 14, 2024

@StarpTech
Author

@mafredri thanks and that would be great!

comunidadio

comunidadio commented on Mar 25, 2025

@comunidadio

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.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mafredri@StarpTech@comunidadio

        Issue actions

          How to get file descriptor from NetConn for EPOLL handling? · Issue #497 · coder/websocket