Retry ioctl when checking TCP socket receive queue len

When checking how much data is left in the receive queue, retry to allow
time for packets to propagate and the system to push data into the
socket's receive queue.

PiperOrigin-RevId: 500257746
This commit is contained in:
Alex Konradi
2023-01-06 15:29:27 -08:00
committed by gVisor bot
parent 3d4743d960
commit d59aa94ac0
+11 -1
View File
@@ -771,8 +771,18 @@ TEST_P(TcpSocketTest, Tiocinq) {
ASSERT_THAT(read, SyscallSucceeds());
size -= read;
// The remaining data should end up in the receive queue.
constexpr absl::Duration kSleepFor = absl::Milliseconds(10);
int inq = 0;
ASSERT_THAT(ioctl(accepted_.get(), TIOCINQ, &inq), SyscallSucceeds());
for (const auto start = absl::Now();
absl::Now() <= start + absl::Milliseconds(kTimeoutMillis);) {
ASSERT_THAT(ioctl(accepted_.get(), TIOCINQ, &inq), SyscallSucceeds());
if (size == inq) {
break;
}
absl::SleepFor(kSleepFor);
}
ASSERT_EQ(inq, size);
}
}