1- use crate :: buf:: BoundedBuf ;
1+ // use crate::buf::BoundedBuf;
22use crate :: io:: SharedFd ;
3- use crate :: runtime:: driver:: op:: { Completable , CqeResult , Op } ;
3+ use crate :: runtime:: driver:: op:: { Completable , CqeResult , MultiCQEFuture , Op , Updateable } ;
44use crate :: runtime:: CONTEXT ;
5- use crate :: BufResult ;
6- use socket2:: SockAddr ;
7- use std:: io:: IoSlice ;
8- use std:: { boxed:: Box , io, net:: SocketAddr } ;
5+ use std:: io;
96
10- pub ( crate ) struct SendMsgZc < T > {
7+ pub ( crate ) struct SendMsgZc {
118 #[ allow( dead_code) ]
129 fd : SharedFd ,
1310
14- /*pub(crate) buf: T,
15-
16- #[allow(dead_code)]
17- io_slices: Vec<IoSlice<'static>>,
18-
19- #[allow(dead_code)]
20- socket_addr: Box<SockAddr>,*/
11+ pub ( crate ) msghdr : libc:: msghdr ,
2112
22- pub ( crate ) msghdr : Box < libc:: msghdr > ,
13+ /// Hold the number of transmitted bytes
14+ bytes : usize ,
2315}
2416
25- impl < T : Box < libc :: msghdr > > Op < SendZc < T > , MultiCQEFuture > {
26- pub ( crate ) fn sendmsg_zc ( fd : & SharedFd , msghdr : Box < libc:: msghdr > ) -> io:: Result < Self > {
17+ impl Op < SendMsgZc , MultiCQEFuture > {
18+ pub ( crate ) fn sendmsg_zc ( fd : & SharedFd , msghdr : & libc:: msghdr ) -> io:: Result < Self > {
2719 use io_uring:: { opcode, types} ;
2820
2921 /*let io_slices = vec![IoSlice::new(unsafe {
@@ -42,28 +34,31 @@ impl<T: Box<libc::msghdr>> Op<SendZc<T>, MultiCQEFuture> {
4234 x. handle ( ) . expect ( "Not in a runtime context" ) . submit_op (
4335 SendMsgZc {
4436 fd : fd. clone ( ) ,
45- /*buf,
46- io_slices,
47- socket_addr,*/
4837 msghdr : msghdr. clone ( ) ,
38+ bytes : 0 ,
4939 } ,
5040 |sendmsg_zc| {
51- opcode:: SendMsgZc :: new ( types:: Fd ( sendmsg_zc. fd . raw_fd ( ) ) , sendmsg_zc. msghdr . as_ref ( ) as * const _ ) . build ( )
41+ opcode:: SendMsgZc :: new ( types:: Fd ( sendmsg_zc. fd . raw_fd ( ) ) , & sendmsg_zc. msghdr as * const _ ) . build ( )
5242 } ,
5343 )
5444 } )
5545 }
5646}
5747
58- impl < T > Completable for SendMsgZc < T > {
59- type Output = BufResult < usize , T > ;
48+ impl Completable for SendMsgZc {
49+ type Output = io :: Result < usize > ;
6050
6151 fn complete ( self , cqe : CqeResult ) -> Self :: Output {
6252 // Convert the operation result to `usize`
6353 let res = cqe. result . map ( |v| v as usize ) ;
64- // Recover the buffer
65- let buf = self . buf ;
54+
55+ res
56+ }
57+ }
6658
67- ( res, buf)
59+ impl Updateable for SendMsgZc {
60+ fn update ( & mut self , cqe : CqeResult ) {
61+ // uring send_zc promises there will be no error on CQE's marked more
62+ self . bytes += * cqe. result . as_ref ( ) . unwrap ( ) as usize ;
6863 }
6964}
0 commit comments