diff options
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) { |