Skip to content

Commit 3373e51

Browse files
authored
Allow more than two receives in test_tcp_recv_bundle (#316)
On my machine with Linux 6.12, 4 receives were needed to drain the socket.
1 parent e1cece4 commit 3373e51

File tree

1 file changed

+17
-37
lines changed

1 file changed

+17
-37
lines changed

io-uring-test/src/tests/net.rs

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,64 +1261,44 @@ pub fn test_tcp_recv_bundle<S: squeue::EntryMarker, C: cqueue::EntryMarker>(
12611261
send_stream.write_all(&input)?;
12621262
send_stream.shutdown(Shutdown::Write)?;
12631263

1264-
let recv_e = opcode::RecvBundle::new(recv_fd, 0xdeff)
1265-
.build()
1266-
.user_data(0x30)
1267-
.into();
1268-
1269-
unsafe {
1270-
ring.submission().push(&recv_e).expect("queue is full");
1271-
}
1272-
1273-
ring.submit_and_wait(1)?;
1274-
1275-
let mut cqe: cqueue::Entry = ring.completion().next().expect("cqueue is empty").into();
1276-
1277-
assert_eq!(cqe.user_data(), 0x30);
1278-
assert!(cqueue::buffer_select(cqe.flags()).is_some());
1279-
let mut remaining = cqe.result() as usize;
1280-
let bufs = buf_ring
1281-
.rc
1282-
.get_bufs(&buf_ring, remaining as u32, cqe.flags());
1283-
let mut section;
12841264
let mut input = input.as_slice();
1285-
for buf in &bufs {
1286-
// In case of bundled recv first bundle may not be full
1287-
let to_check = std::cmp::min(256, remaining);
1288-
(section, input) = input.split_at(to_check);
1289-
assert_eq!(buf.as_slice(), section);
1290-
remaining -= to_check;
1291-
}
1292-
assert_eq!(remaining, 0);
12931265

1294-
// Linux kernel 6.10 packs a single buffer into first recv and remaining buffers into second recv
1295-
// This behavior may change in the future
1296-
if !input.is_empty() {
1297-
assert!(cqueue::sock_nonempty(cqe.flags()));
1266+
// Multiple receive operations might be needed to receive everything.
1267+
loop {
1268+
let recv_e = opcode::RecvBundle::new(recv_fd, 0xdeff)
1269+
.build()
1270+
.user_data(0x30)
1271+
.into();
12981272

12991273
unsafe {
13001274
ring.submission().push(&recv_e).expect("queue is full");
13011275
}
13021276

13031277
ring.submit_and_wait(1)?;
13041278

1305-
cqe = ring.completion().next().expect("cqueue is empty").into();
1279+
let cqe: cqueue::Entry = ring.completion().next().expect("cqueue is empty").into();
13061280

13071281
assert_eq!(cqe.user_data(), 0x30);
13081282
assert!(cqueue::buffer_select(cqe.flags()).is_some());
1309-
remaining = cqe.result() as usize;
1310-
let second_bufs = buf_ring
1283+
let mut remaining = cqe.result() as usize;
1284+
let bufs = buf_ring
13111285
.rc
13121286
.get_bufs(&buf_ring, remaining as u32, cqe.flags());
1313-
for buf in &second_bufs {
1287+
let mut section;
1288+
for buf in &bufs {
13141289
let to_check = std::cmp::min(256, remaining);
13151290
(section, input) = input.split_at(to_check);
13161291
assert_eq!(buf.as_slice(), section);
13171292
remaining -= to_check;
13181293
}
13191294
assert_eq!(remaining, 0);
1295+
1296+
if input.is_empty() {
1297+
break;
1298+
}
1299+
1300+
assert!(cqueue::sock_nonempty(cqe.flags()));
13201301
}
1321-
assert!(input.is_empty());
13221302

13231303
buf_ring.rc.unregister(ring)?;
13241304

0 commit comments

Comments
 (0)