@@ -7,18 +7,23 @@ use std::{
7
7
{ boxed:: Box , io, net:: SocketAddr } ,
8
8
} ;
9
9
10
- pub ( crate ) struct RecvMsg < T > {
10
+ pub ( crate ) struct RecvMsg < T , U = Vec < u8 > > {
11
11
#[ allow( dead_code) ]
12
12
fd : SharedFd ,
13
13
pub ( crate ) buf : Vec < T > ,
14
14
#[ allow( dead_code) ]
15
15
io_slices : Vec < IoSliceMut < ' static > > ,
16
16
pub ( crate ) socket_addr : Box < SockAddr > ,
17
+ pub ( crate ) msg_control : Option < U > ,
17
18
pub ( crate ) msghdr : Box < libc:: msghdr > ,
18
19
}
19
20
20
- impl < T : BoundedBufMut > Op < RecvMsg < T > > {
21
- pub ( crate ) fn recvmsg ( fd : & SharedFd , mut bufs : Vec < T > ) -> io:: Result < Op < RecvMsg < T > > > {
21
+ impl < T : BoundedBufMut , U : BoundedBufMut > Op < RecvMsg < T , U > > {
22
+ pub ( crate ) fn recvmsg (
23
+ fd : & SharedFd ,
24
+ mut bufs : Vec < T > ,
25
+ mut msg_control : Option < U > ,
26
+ ) -> io:: Result < Op < RecvMsg < T , U > > > {
22
27
use io_uring:: { opcode, types} ;
23
28
24
29
let mut io_slices = Vec :: with_capacity ( bufs. len ( ) ) ;
@@ -35,6 +40,10 @@ impl<T: BoundedBufMut> Op<RecvMsg<T>> {
35
40
msghdr. msg_iovlen = io_slices. len ( ) as _ ;
36
41
msghdr. msg_name = socket_addr. as_ptr ( ) as * mut libc:: c_void ;
37
42
msghdr. msg_namelen = socket_addr. len ( ) ;
43
+ if let Some ( msg_control) = & mut msg_control {
44
+ msghdr. msg_control = msg_control. stable_mut_ptr ( ) . cast ( ) ;
45
+ msghdr. msg_controllen = msg_control. bytes_total ( ) ;
46
+ }
38
47
39
48
CONTEXT . with ( |x| {
40
49
x. handle ( ) . expect ( "Not in a runtime context" ) . submit_op (
@@ -43,6 +52,7 @@ impl<T: BoundedBufMut> Op<RecvMsg<T>> {
43
52
buf : bufs,
44
53
io_slices,
45
54
socket_addr,
55
+ msg_control,
46
56
msghdr,
47
57
} ,
48
58
|recv_from| {
@@ -57,11 +67,12 @@ impl<T: BoundedBufMut> Op<RecvMsg<T>> {
57
67
}
58
68
}
59
69
60
- impl < T > Completable for RecvMsg < T >
70
+ impl < T , U > Completable for RecvMsg < T , U >
61
71
where
62
72
T : BoundedBufMut ,
73
+ U : BoundedBufMut ,
63
74
{
64
- type Output = BufResult < ( usize , SocketAddr ) , Vec < T > > ;
75
+ type Output = BufResult < ( usize , SocketAddr , Option < U > ) , Vec < T > > ;
65
76
66
77
fn complete ( self , cqe : CqeResult ) -> Self :: Output {
67
78
// Convert the operation result to `usize`
71
82
72
83
let socket_addr = ( * self . socket_addr ) . as_socket ( ) ;
73
84
85
+ let msg_control = self . msg_control ;
86
+
74
87
let res = res. map ( |n| {
75
88
let socket_addr: SocketAddr = socket_addr. unwrap ( ) ;
76
89
89
102
break ;
90
103
}
91
104
}
92
- ( n, socket_addr)
105
+ ( n, socket_addr, msg_control )
93
106
} ) ;
94
107
95
108
( res, bufs)
0 commit comments