@@ -1575,6 +1575,79 @@ pub fn test_udp_recvmsg_multishot_trunc<S: squeue::EntryMarker, C: cqueue::Entry
1575
1575
1576
1576
Ok ( ( ) )
1577
1577
}
1578
+
1579
+ pub fn test_udp_send_with_dest < S : squeue:: EntryMarker , C : cqueue:: EntryMarker > (
1580
+ ring : & mut IoUring < S , C > ,
1581
+ test : & Test ,
1582
+ ) -> anyhow:: Result < ( ) > {
1583
+ require ! (
1584
+ test;
1585
+ test. probe. is_supported( opcode:: Recv :: CODE ) ;
1586
+ test. probe. is_supported( opcode:: Send :: CODE ) ;
1587
+ ) ;
1588
+
1589
+ println ! ( "test udp_send_with_dest" ) ;
1590
+
1591
+ let socket: socket2:: Socket = std:: net:: UdpSocket :: bind ( "127.0.0.1:0" ) . unwrap ( ) . into ( ) ;
1592
+ let addr = socket. local_addr ( ) ?;
1593
+ let fd = Fd ( socket. as_raw_fd ( ) ) ;
1594
+
1595
+ // We are going to do a send below. To confirm that it works, start a
1596
+ // recv to receive the data sent by the send.
1597
+ let mut in_buf = vec ! [ 0 ; 1024 ] ;
1598
+ let recv = opcode:: Recv :: new ( fd, in_buf. as_mut_ptr ( ) , in_buf. len ( ) as u32 )
1599
+ . build ( )
1600
+ . user_data ( 1 )
1601
+ . into ( ) ;
1602
+
1603
+ let out_buf = b"test message" ;
1604
+
1605
+ // For the first send, we don't specify a destination address. This should
1606
+ // result in an error.
1607
+ let send1 = opcode:: Send :: new ( fd, out_buf. as_ptr ( ) , out_buf. len ( ) as u32 )
1608
+ . build ( )
1609
+ . user_data ( 2 )
1610
+ . into ( ) ;
1611
+
1612
+ // For the second send, we do specify the destination address, and we should
1613
+ // receive our test message there.
1614
+ let send2 = opcode:: Send :: new ( fd, out_buf. as_ptr ( ) , out_buf. len ( ) as u32 )
1615
+ . dest_addr ( addr. as_ptr ( ) )
1616
+ . dest_addr_len ( addr. len ( ) )
1617
+ . build ( )
1618
+ . user_data ( 3 )
1619
+ . into ( ) ;
1620
+
1621
+ unsafe { ring. submission ( ) . push_multiple ( & [ recv, send1, send2] ) ? } ;
1622
+ ring. submitter ( ) . submit_and_wait ( 3 ) ?;
1623
+
1624
+ let cqes: Vec < cqueue:: Entry > = ring. completion ( ) . map ( Into :: into) . collect ( ) ;
1625
+ assert_eq ! ( cqes. len( ) , 3 ) ;
1626
+
1627
+ for cqe in cqes {
1628
+ match cqe. user_data ( ) {
1629
+ 1 => {
1630
+ // The receive, we should have received the test message here.
1631
+ let n_received = cqe. result ( ) ;
1632
+ assert_eq ! ( n_received, out_buf. len( ) as i32 ) ;
1633
+ assert_eq ! ( & in_buf[ ..n_received as usize ] , out_buf) ;
1634
+ }
1635
+ 2 => {
1636
+ // The send should have failed because it had no destination address.
1637
+ assert_eq ! ( cqe. result( ) , -libc:: EDESTADDRREQ ) ;
1638
+ }
1639
+ 3 => {
1640
+ // The send that should have succeeded.
1641
+ let n_sent = cqe. result ( ) ;
1642
+ assert_eq ! ( n_sent, out_buf. len( ) as i32 ) ;
1643
+ }
1644
+ _ => unreachable ! ( "We only submit user data 1, 2, and 3." ) ,
1645
+ }
1646
+ }
1647
+
1648
+ Ok ( ( ) )
1649
+ }
1650
+
1578
1651
pub fn test_udp_sendzc_with_dest < S : squeue:: EntryMarker , C : cqueue:: EntryMarker > (
1579
1652
ring : & mut IoUring < S , C > ,
1580
1653
test : & Test ,
0 commit comments