diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-04-13 23:04:01 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-04-13 23:05:08 -0700 |
commit | c230d12b5ce540239df06e517f3b1b72722dcc14 (patch) | |
tree | 4c191ea971d550cd9c446a502d2b8d33fe939195 /test/packetimpact/testbench/connections.go | |
parent | 71e6ac3e1f551cf52166bf501de114f06502b994 (diff) |
Add Sniffer.Drain() draining socket receive buffer
Add Sniffer.Drain() which drains the socket's receive buffer by temporarily
setting the socket to non-blocking, and receiving in a loop until EINTR,
EWOULDBLOCK or EAGAIN. This method should be used when long periods of time
elapses without receiving on the socket, because uninteresting packets may have
piled up in the receive buffer, filling it up and causing packets critical to
test operation to be dropped.
PiperOrigin-RevId: 306380480
Diffstat (limited to 'test/packetimpact/testbench/connections.go')
-rw-r--r-- | test/packetimpact/testbench/connections.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/packetimpact/testbench/connections.go b/test/packetimpact/testbench/connections.go index 79c0ccf5c..2b8e2f005 100644 --- a/test/packetimpact/testbench/connections.go +++ b/test/packetimpact/testbench/connections.go @@ -228,6 +228,12 @@ func (conn *TCPIPv4) RecvFrame(timeout time.Duration) Layers { return nil } +// Drain drains the sniffer's receive buffer by receiving packets until there's +// nothing else to receive. +func (conn *TCPIPv4) Drain() { + conn.sniffer.Drain() +} + // Expect a packet that matches the provided tcp within the timeout specified. // If it doesn't arrive in time, it returns nil. func (conn *TCPIPv4) Expect(tcp TCP, timeout time.Duration) (*TCP, error) { @@ -423,6 +429,12 @@ func (conn *UDPIPv4) Recv(timeout time.Duration) *UDP { return nil } +// Drain drains the sniffer's receive buffer by receiving packets until there's +// nothing else to receive. +func (conn *UDPIPv4) Drain() { + conn.sniffer.Drain() +} + // Expect a packet that matches the provided udp within the timeout specified. // If it doesn't arrive in time, the test fails. func (conn *UDPIPv4) Expect(udp UDP, timeout time.Duration) (*UDP, error) { |