Skip to content

Conversation

marten-seemann
Copy link

Currently, the connection passed to NewConn has to be a *net.TCPConn, even though the function allows for a net.Conn to be passed. This is because NewConn performs a type assertion:

tcp/rawconn.go

Lines 99 to 112 in 803a9b4

func NewConn(c net.Conn) (*Conn, error) {
cc := &Conn{Conn: c}
switch c := c.(type) {
case *net.TCPConn:
var err error
cc.c, err = c.SyscallConn()
if err != nil {
return nil, err
}
return cc, nil
default:
return nil, errors.New("unknown connection type")
}
}

It would be nice if it was possible to pass a wrapped *net.TCPConn to NewConn. This should be a problem, as the only function actually needed is SyscallConn(). By doing an interface assertion using an interface only fulfilled by a net.TCPConn, we can even make sure that we don't accidentally use this package with a connection that's not a TCP connection.

@marten-seemann
Copy link
Author

@mikioh Any thought about this PR?

@marten-seemann
Copy link
Author

@mikioh Friendly ping.
It would be really great if we could get this PR merged soon, I'd hate to fork this project for such a minor change.

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

Successfully merging this pull request may close these issues.

1 participant