Skip to content

Commit

Permalink
Adds KernelExt::listen
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon committed May 22, 2024
1 parent 30145ee commit 82617e3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ pub trait KernelExt: Kernel {
nam: &mut SockAddr,
td: *mut Self::Thread,
) -> Result<(), NonZeroI32>;

/// # Safety
/// - `so` cannot be null.
/// - `td` cannot be null.
unsafe fn listen(
self,
so: *mut Self::Socket,
backlog: c_int,
td: *mut Self::Thread,
) -> Result<(), NonZeroI32>;
}

impl<T: Kernel> KernelExt for T {
Expand Down Expand Up @@ -84,4 +94,18 @@ impl<T: Kernel> KernelExt for T {
None => Ok(()),
}
}

unsafe fn listen(
self,
so: *mut Self::Socket,
backlog: c_int,
td: *mut Self::Thread,
) -> Result<(), NonZeroI32> {
let errno = self.solisten(so, backlog, td);

match NonZeroI32::new(errno) {
Some(v) => Err(v),
None => Ok(()),
}
}
}

0 comments on commit 82617e3

Please sign in to comment.