From 82617e3449bc95d5469b1460b727ea1a9d9a99a8 Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Wed, 22 May 2024 16:40:22 +0700 Subject: [PATCH] Adds KernelExt::listen --- src/ext.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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(()), + } + } }