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

Support creating O_NONBLOCK scheme sockets.

parent 851272ff
No related branches found
No related tags found
No related merge requests found
...@@ -119,11 +119,22 @@ impl Request { ...@@ -119,11 +119,22 @@ impl Request {
pub struct Socket(libredox::Fd); pub struct Socket(libredox::Fd);
impl Socket { impl Socket {
pub fn create(name: impl AsRef<str>) -> Result<Self> { fn create_inner(name: &str, nonblock: bool) -> Result<Self> {
let name = name.as_ref(); let mut flags = 0;
let fd = libredox::Fd::open(&format!(":{name}"), flag::O_CLOEXEC | flag::O_CREAT, 0)?;
if nonblock {
flags |= flag::O_NONBLOCK;
}
let fd = libredox::Fd::open(&format!(":{name}"), flag::O_CLOEXEC | flag::O_CREAT | flags, 0)?;
Ok(Self(fd)) Ok(Self(fd))
} }
pub fn create(name: impl AsRef<str>) -> Result<Self> {
Self::create_inner(name.as_ref(), false)
}
pub fn nonblock(name: impl AsRef<str>) -> Result<Self> {
Self::create_inner(name.as_ref(), true)
}
pub fn read_requests(&self, buf: &mut [Request], behavior: SignalBehavior) -> Result<usize> { pub fn read_requests(&self, buf: &mut [Request], behavior: SignalBehavior) -> Result<usize> {
read_requests(self.0.raw(), buf, behavior) read_requests(self.0.raw(), buf, behavior)
} }
......
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