diff --git a/io-uring-test/src/tests/net.rs b/io-uring-test/src/tests/net.rs index 02e3631..23d234a 100644 --- a/io-uring-test/src/tests/net.rs +++ b/io-uring-test/src/tests/net.rs @@ -1447,7 +1447,6 @@ pub fn test_udp_recvmsg_multishot_trunc() + msghdr.msg_namelen let mut buf2 = [0u8; 20 + DATA.len()]; - let mut buf3 = [0u8; 20 + DATA.len()]; - let mut buffers = [ - buf1.as_mut_slice(), - buf2.as_mut_slice(), - buf3.as_mut_slice(), - ]; + let mut buffers = [buf1.as_mut_slice(), buf2.as_mut_slice()]; for (index, buf) in buffers.iter_mut().enumerate() { - let provide_bufs_e = io_uring::opcode::ProvideBuffers::new( + let provide_bufs_e = opcode::ProvideBuffers::new( (**buf).as_mut_ptr(), buf.len() as i32, 1, @@ -1479,7 +1473,7 @@ pub fn test_udp_recvmsg_multishot_trunc = ring.completion().map(Into::into).collect(); + let cqes: Vec = ring.completion().map(Into::into).collect(); assert_eq!(cqes.len(), 1); assert_eq!(cqes[0].user_data(), 11); assert_eq!(cqes[0].result(), 0); @@ -1488,7 +1482,7 @@ pub fn test_udp_recvmsg_multishot_trunc = ring.completion().map(Into::into).collect(); - assert_eq!(cqes.len(), 4); - let mut i = 0; + let cqes: Vec = ring.completion().map(Into::into).collect(); + // Older kernels have "reactive" RecvMsg in that RecvMsg will wait to claim a buffer + // until there is a message. Newer kernels are "proactive" in that they immediately + // claim a buffer without knowing whether or not there are messages to be received + // which means we can get an extra CQE saying we ran out of buffers. + assert!(4 <= cqes.len() && cqes.len() <= 5, "{}", cqes.len()); for cqe in cqes { - let is_more = io_uring::cqueue::more(cqe.flags()); + let is_more = cqueue::more(cqe.flags()); match cqe.user_data() { // send notifications 55 => { @@ -1537,13 +1534,18 @@ pub fn test_udp_recvmsg_multishot_trunc { + if cqe.result() == -105 { + // Ran out of buffers + continue; + } + assert!(cqe.result() > 0); assert!(is_more); - let buf_id = io_uring::cqueue::buffer_select(cqe.flags()).unwrap(); + let buf_id = cqueue::buffer_select(cqe.flags()).unwrap(); let tmp_buf = &buffers[buf_id as usize]; let msg = types::RecvMsgOut::parse(tmp_buf, &msghdr); - match i { + match buf_id { 0 => { let msg = msg.unwrap(); assert!(msg.is_payload_truncated()); @@ -1564,7 +1566,6 @@ pub fn test_udp_recvmsg_multishot_trunc unreachable!(), } - i += 1; } _ => { unreachable!()