From e44b100654ca639d11221e547384f699e461296d Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Thu, 7 Oct 2021 17:37:50 -0700 Subject: add convenient wrapper for eventfd The same create/write/read pattern is copied around several places. It's easier to understand in a package with names and comments, and we can reuse the smart blocking code in package rawfile. PiperOrigin-RevId: 401647108 --- pkg/tcpip/link/sharedmem/server_tx.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'pkg/tcpip/link/sharedmem/server_tx.go') diff --git a/pkg/tcpip/link/sharedmem/server_tx.go b/pkg/tcpip/link/sharedmem/server_tx.go index 9370b2a46..13a82903f 100644 --- a/pkg/tcpip/link/sharedmem/server_tx.go +++ b/pkg/tcpip/link/sharedmem/server_tx.go @@ -20,6 +20,7 @@ package sharedmem import ( "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/cleanup" + "gvisor.dev/gvisor/pkg/eventfd" "gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/link/sharedmem/pipe" "gvisor.dev/gvisor/pkg/tcpip/link/sharedmem/queue" @@ -40,7 +41,7 @@ type serverTx struct { data []byte // eventFD is used to notify the peer when fill requests are fulfilled. - eventFD int + eventFD eventfd.Eventfd // sharedData the memory region to use to enable/disable notifications. sharedData []byte @@ -80,16 +81,11 @@ func (s *serverTx) init(c *QueueConfig) error { // Duplicate the eventFD so that caller can close it but we can still // use it. - efd, err := unix.Dup(c.EventFD) + efd, err := c.EventFD.Dup() if err != nil { return err } - cu.Add(func() { unix.Close(efd) }) - - // Set the eventfd as non-blocking. - if err := unix.SetNonblock(efd, true); err != nil { - return err - } + cu.Add(func() { efd.Close() }) cu.Release() @@ -107,7 +103,7 @@ func (s *serverTx) cleanup() { unix.Munmap(s.completionPipe.Bytes()) unix.Munmap(s.data) unix.Munmap(s.sharedData) - unix.Close(s.eventFD) + s.eventFD.Close() } // fillPacket copies the data in the provided views into buffers pulled from the @@ -175,5 +171,5 @@ func (s *serverTx) transmit(views []buffer.View) bool { } func (s *serverTx) notify() { - unix.Write(s.eventFD, []byte{1, 0, 0, 0, 0, 0, 0, 0}) + s.eventFD.Notify() } -- cgit v1.2.3