diff --git a/src/lib.rs b/src/lib.rs index d396b805fb661aa849c33cc4f01ca4fb18be7dc7..daa0916cd284e1ca42996f9aba6ce3faf6bf7242 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,7 +215,7 @@ impl Socket { pub struct Response(Cqe); impl Response { - pub fn new(req: impl IntoTag, status: Result<usize>) -> Self { + pub fn new(status: Result<usize>, req: impl IntoTag) -> Self { Self(Cqe { flags: CqeOpcode::RespondRegular as u8, extra_raw: [0_u8; 3], @@ -223,16 +223,16 @@ impl Response { tag: req.into_tag().0 .0, }) } - pub fn open_dup_like(req: impl IntoTag, res: Result<OpenResult>) -> Response { + pub fn open_dup_like(res: Result<OpenResult>, req: impl IntoTag) -> Response { match res { Ok(OpenResult::ThisScheme { number, flags }) => { - Response::new(req, Ok(number)).with_extra([flags.bits(), 0, 0]) + Response::new(Ok(number), req).with_extra([flags.bits(), 0, 0]) } - Err(e) => Response::new(req, Err(e)), - Ok(OpenResult::OtherScheme { fd }) => Response::return_external_fd(req, fd), + Err(e) => Response::new(Err(e), req), + Ok(OpenResult::OtherScheme { fd }) => Response::return_external_fd(fd, req), } } - pub fn return_external_fd(req: impl IntoTag, fd: usize) -> Self { + pub fn return_external_fd(fd: usize, req: impl IntoTag) -> Self { Self(Cqe { flags: CqeOpcode::RespondWithFd as u8, extra_raw: [0_u8; 3], diff --git a/src/scheme.rs b/src/scheme.rs index 093cb00126aa914055ea95e1307d6d11ca5cd431..0981252d9030378c5f564c3ff69de4cebe06154c 100644 --- a/src/scheme.rs +++ b/src/scheme.rs @@ -366,13 +366,13 @@ impl CallRequest { let op = match self.op() { Ok(op) => op, - Err(this) => return Ok(Response::new(this, Err(Error::new(ENOSYS)))), + Err(this) => return Ok(Response::new(Err(Error::new(ENOSYS)), this)), }; let (res, tag) = match op { Op::Open(req) => { let res = s.open(req.path(), req.flags, &caller).await; - return Ok(Response::open_dup_like(req, res)); + return Ok(Response::open_dup_like(res, req)); } Op::Rmdir(req) => ( s.rmdir(req.path(), &caller).await.map(|()| 0), @@ -385,7 +385,7 @@ impl CallRequest { Op::Dup(req) => { let res = s.dup(req.fd, req.buf(), &caller).await; - return Ok(Response::open_dup_like(req, res)); + return Ok(Response::open_dup_like(res, req)); } Op::Read(mut req) => { let OpRead { @@ -475,7 +475,7 @@ impl CallRequest { (Ok(buf.finalize()), req.into_tag()) } }; - Ok(Response::new(tag, res)) + Ok(Response::new(res, tag)) } // TODO: Fix function coloring, this is just s/.await//g pub fn handle_sync(self, s: &mut impl SchemeSync) -> Result<Response> { @@ -483,20 +483,20 @@ impl CallRequest { let op = match self.op() { Ok(op) => op, - Err(this) => return Ok(Response::new(this, Err(Error::new(ENOSYS)))), + Err(this) => return Ok(Response::new(Err(Error::new(ENOSYS)), this)), }; let (res, tag) = match op { Op::Open(req) => { let res = s.open(req.path(), req.flags, &caller); - return Ok(Response::open_dup_like(req, res)); + return Ok(Response::open_dup_like(res, req)); } Op::Rmdir(req) => (s.rmdir(req.path(), &caller).map(|()| 0), req.into_tag()), Op::Unlink(req) => (s.unlink(req.path(), &caller).map(|()| 0), req.into_tag()), Op::Dup(req) => { let res = s.dup(req.fd, req.buf(), &caller); - return Ok(Response::open_dup_like(req, res)); + return Ok(Response::open_dup_like(res, req)); } Op::Read(mut req) => { let OpRead { @@ -574,7 +574,7 @@ impl CallRequest { (Ok(buf.finalize()), req.into_tag()) } }; - Ok(Response::new(tag, res)) + Ok(Response::new(res, tag)) } }