diff --git a/src/ext.rs b/src/ext.rs index 9d67821..a389320 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -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 KernelExt for T { @@ -84,4 +94,18 @@ impl 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(()), + } + } }