Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ func TestConn(t *testing.T) {
return tc, p.Conn, func() { tc.Close(); p.Conn.Close() }, nil
})
}

func TestWrappedConn(t *testing.T) {
type wrappedConn struct{ *net.TCPConn }
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatal(err)
}
conn, err := net.DialTCP("tcp", nil, ln.Addr().(*net.TCPAddr))
if err != nil {
t.Fatal(err)
}
if _, err = tcp.NewConn(&wrappedConn{conn}); err != nil {
t.Fatalf("couldn't initialize from a wrapped conn: %v", err)
}
}
7 changes: 6 additions & 1 deletion rawconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ func (c *Conn) available() int {

// NewConn returns a new end point.
func NewConn(c net.Conn) (*Conn, error) {
type tcpConn interface {
SyscallConn() (syscall.RawConn, error)
SetLinger(int) error
}
var _ tcpConn = &net.TCPConn{}
cc := &Conn{Conn: c}
switch c := c.(type) {
case *net.TCPConn:
case tcpConn:
var err error
cc.c, err = c.SyscallConn()
if err != nil {
Expand Down