Skip to content
Snippets Groups Projects
Commit c0741452 authored by Jacob Lorentzon's avatar Jacob Lorentzon
Browse files

Add convenience fns for creating Response.

parent ad9ef75f
No related branches found
No related tags found
2 merge requests!6Redesign API to fix (most) soundness and add async support.,!5Draft: Improved async-capable interface
...@@ -4,6 +4,7 @@ extern crate alloc; ...@@ -4,6 +4,7 @@ extern crate alloc;
use alloc::format; use alloc::format;
use core::str; use core::str;
use core::task::Poll;
use libredox::flag; use libredox::flag;
use syscall::error::{Error, Result, EINTR}; use syscall::error::{Error, Result, EINTR};
...@@ -215,6 +216,23 @@ impl Socket { ...@@ -215,6 +216,23 @@ impl Socket {
pub struct Response(Cqe); pub struct Response(Cqe);
impl Response { impl Response {
#[inline]
pub fn err(err: i32, req: impl IntoTag) -> Self {
Self::new(Err(Error::new(err)), req)
}
#[inline]
pub fn ok(status: usize, req: impl IntoTag) -> Self {
Self::new(Ok(status), req)
}
#[inline]
pub fn ready_ok(status: usize, req: impl IntoTag) -> Poll<Self> {
Poll::Ready(Self::ok(status, req))
}
#[inline]
pub fn ready_err(err: i32, req: impl IntoTag) -> Poll<Self> {
Poll::Ready(Self::err(err, req))
}
pub fn new(status: Result<usize>, req: impl IntoTag) -> Self { pub fn new(status: Result<usize>, req: impl IntoTag) -> Self {
Self(Cqe { Self(Cqe {
flags: CqeOpcode::RespondRegular as u8, flags: CqeOpcode::RespondRegular as u8,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment