From 385f86e85f4af1876aa723a6f50b5b09324543ea Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 8 Jul 2021 12:09:54 -0700 Subject: [PATCH] document, cull dead code --- net/uring/io_uring_linux.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/net/uring/io_uring_linux.go b/net/uring/io_uring_linux.go index 91a43a3ef..1882a58f7 100644 --- a/net/uring/io_uring_linux.go +++ b/net/uring/io_uring_linux.go @@ -32,11 +32,14 @@ const bufferSize = device.MaxSegmentSize // That's OK for now, but later it could be a performance issue. // For now, keep it simple and enqueue/dequeue in a single step. type UDPConn struct { + // We have two urings so that we don't have to demux completion events. + // recvRing is the uring for recvmsg calls. recvRing *C.go_uring + // sendRing is the uring for sendmsg calls. sendRing *C.go_uring - close sync.Once - conn *net.UDPConn - file *os.File // must keep file from being GC'd + // close ensures that connection closes occur exactly once. + close sync.Once + file *os.File // must keep file from being GC'd // fd is the underlying fd associated with this connection. // It is set to zero when the connection closes. // It is accessed atomically. @@ -74,6 +77,8 @@ func NewUDPConn(pconn net.PacketConn) (*UDPConn, error) { if err != nil { return nil, err } + // conn.File dup'd the conn's fd. We no longer need the original conn. + conn.Close() recvRing := new(C.go_uring) sendRing := new(C.go_uring) @@ -88,7 +93,6 @@ func NewUDPConn(pconn net.PacketConn) (*UDPConn, error) { u := &UDPConn{ recvRing: recvRing, sendRing: sendRing, - conn: conn, file: file, fd: fd, local: conn.LocalAddr(), @@ -162,10 +166,6 @@ func (u *UDPConn) ReadFromNetaddr(buf []byte) (int, netaddr.IPPort, error) { u.submitRecvRequest(int(idx)) return 0, netaddr.IPPort{}, fmt.Errorf("ReadFromNetaddr syscall failed: %w", syscall.Errno(-n)) } - // Received nop. - if idx == -1 { - return 0, netaddr.IPPort{}, nil - } r := u.recvReqs[idx] var ip netaddr.IP var port uint16 @@ -219,8 +219,6 @@ func (u *UDPConn) Close() error { break BusyLoop } } - u.conn.Close() - u.conn = nil u.file.Close() u.file = nil // TODO: block until no one else uses our rings.