Skip to content

Commit fc8c89a

Browse files
committed
Updated SendMsgZc stuff.
1 parent 78f3f77 commit fc8c89a

File tree

3 files changed

+23
-28
lines changed

3 files changed

+23
-28
lines changed

src/io/sendmsg_zc.rs

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
use crate::buf::BoundedBuf;
1+
//use crate::buf::BoundedBuf;
22
use crate::io::SharedFd;
3-
use crate::runtime::driver::op::{Completable, CqeResult, Op};
3+
use crate::runtime::driver::op::{Completable, CqeResult, MultiCQEFuture, Op, Updateable};
44
use 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
}

src/io/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Socket {
147147
op.await
148148
}
149149

150-
pub(crate) async fn sendmsg_zc<T: Box<libc::msghdr>(&self, msghdr: T) -> crate::BufResult<usize, T> {
150+
pub(crate) async fn sendmsg_zc(&self, msghdr: &libc::msghdr) -> io::Result<usize> {
151151
let op = Op::sendmsg_zc(&self.fd, msghdr).unwrap();
152152
op.await
153153
}

src/net/udp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl UdpSocket {
220220
self.inner.send_zc(buf).await
221221
}
222222

223-
pub async fn sendmsg_zc<T: Box<libc::msghdr>>(&self, msghdr: T) -> crate::BufResult<usize, T> {
223+
pub async fn sendmsg_zc(&self, msghdr: &libc::msghdr) -> io::Result<usize> {
224224
self.inner.sendmsg_zc(msghdr).await
225225
}
226226

0 commit comments

Comments
 (0)