From 45398b160f4ccc3148644dde5eb5e4610e6a2d9b Mon Sep 17 00:00:00 2001 From: Marek Majkowski Date: Wed, 22 Jan 2020 12:50:28 +0000 Subject: Expose gonet.NewPacketConn, for parity with gonet.NewConn API gonet.Conn can be created with both gonet.NewConn and gonet.Dial. gonet.PacketConn was created only by gonet.DialUDP. This prevented us from being able to use PacketConn in udp.NewForwarder() context. This simple constructor - NewPacketConn, allows user to create correct structure from that context. --- pkg/tcpip/adapters/gonet/gonet.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'pkg') diff --git a/pkg/tcpip/adapters/gonet/gonet.go b/pkg/tcpip/adapters/gonet/gonet.go index 3bba4028b..b659cfccf 100644 --- a/pkg/tcpip/adapters/gonet/gonet.go +++ b/pkg/tcpip/adapters/gonet/gonet.go @@ -556,6 +556,17 @@ type PacketConn struct { wq *waiter.Queue } +// NewPacketConn creates a new PacketConn. +func NewPacketConn(s *stack.Stack, wq *waiter.Queue, ep tcpip.Endpoint) *PacketConn { + c := &PacketConn{ + stack: s, + ep: ep, + wq: wq, + } + c.deadlineTimer.init() + return c +} + // DialUDP creates a new PacketConn. // // If laddr is nil, a local address is automatically chosen. -- cgit v1.2.3