diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-03-23 16:06:09 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-03-23 16:06:09 +0100 |
commit | 949465eb30dfbe1616d3e376acdfd439fbb3ebe8 (patch) | |
tree | 9ac66b8207a943a9658e0c64264bedc714d4889f /pkg/tcpip/link/fdbased/packet_dispatchers.go | |
parent | c67d7372613acf80dd49fd0128f40753d4787c5a (diff) | |
parent | 2984c175550d3c9ce304e4678a328957ddf9a37f (diff) |
Merge branch 'detachable-fdbased' into go-detachable-fdbased2go-detachable-fdbased
Diffstat (limited to 'pkg/tcpip/link/fdbased/packet_dispatchers.go')
-rw-r--r-- | pkg/tcpip/link/fdbased/packet_dispatchers.go | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/pkg/tcpip/link/fdbased/packet_dispatchers.go b/pkg/tcpip/link/fdbased/packet_dispatchers.go index a7adf822b..9deee81ac 100644 --- a/pkg/tcpip/link/fdbased/packet_dispatchers.go +++ b/pkg/tcpip/link/fdbased/packet_dispatchers.go @@ -17,6 +17,8 @@ package fdbased import ( + "os" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/tcpip" "gvisor.dev/gvisor/pkg/tcpip/buffer" @@ -124,18 +126,29 @@ type readVDispatcher struct { // buf is the iovec buffer that contains the packet contents. buf *iovecBuffer + + cancelRead *os.File + cancelWrite *os.File } func newReadVDispatcher(fd int, e *endpoint) (linkDispatcher, error) { - d := &readVDispatcher{fd: fd, e: e} + cancelRead, cancelWrite, err := os.Pipe() + if err != nil { + return nil, err + } + d := &readVDispatcher{fd: fd, e: e, cancelRead: cancelRead, cancelWrite: cancelWrite} skipsVnetHdr := d.e.Capabilities()&stack.CapabilityHardwareGSO != 0 d.buf = newIovecBuffer(BufConfig, skipsVnetHdr) return d, nil } +func (d *readVDispatcher) Cancel() { + d.cancelWrite.Write([]byte{0}) +} + // dispatch reads one packet from the file descriptor and dispatches it. func (d *readVDispatcher) dispatch() (bool, tcpip.Error) { - n, err := rawfile.BlockingReadv(d.fd, d.buf.nextIovecs()) + n, err := rawfile.BlockingReadvWithCancel(d.fd, d.buf.nextIovecs(), d.cancelRead) if n == 0 || err != nil { return false, err } @@ -219,6 +232,10 @@ func newRecvMMsgDispatcher(fd int, e *endpoint) (linkDispatcher, error) { return d, nil } +func (d *recvMMsgDispatcher) Cancel() { + // TODO +} + // recvMMsgDispatch reads more than one packet at a time from the file // descriptor and dispatches it. func (d *recvMMsgDispatcher) dispatch() (bool, tcpip.Error) { |