From 148f3acd620d6f417636ab34b99bfa5f9ee595d4 Mon Sep 17 00:00:00 2001 From: Asakura Mizu Date: Tue, 27 Aug 2024 21:26:08 +0800 Subject: [PATCH] chore(net): add type constraint for get/set_socket_option --- compio-net/src/socket.rs | 18 ++++++++++++++---- compio-net/src/udp.rs | 9 +++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/compio-net/src/socket.rs b/compio-net/src/socket.rs index 03bb8b27..31f6d6be 100644 --- a/compio-net/src/socket.rs +++ b/compio-net/src/socket.rs @@ -324,7 +324,7 @@ impl Socket { } #[cfg(unix)] - pub unsafe fn get_socket_option(&self, level: i32, name: i32) -> io::Result { + pub unsafe fn get_socket_option(&self, level: i32, name: i32) -> io::Result { let mut value: MaybeUninit = MaybeUninit::uninit(); let mut len = size_of::() as libc::socklen_t; syscall!(libc::getsockopt( @@ -342,7 +342,7 @@ impl Socket { } #[cfg(windows)] - pub unsafe fn get_socket_option(&self, level: i32, name: i32) -> io::Result { + pub unsafe fn get_socket_option(&self, level: i32, name: i32) -> io::Result { let mut value: MaybeUninit = MaybeUninit::uninit(); let mut len = size_of::() as i32; syscall!( @@ -363,7 +363,12 @@ impl Socket { } #[cfg(unix)] - pub unsafe fn set_socket_option(&self, level: i32, name: i32, value: &T) -> io::Result<()> { + pub unsafe fn set_socket_option( + &self, + level: i32, + name: i32, + value: &T, + ) -> io::Result<()> { syscall!(libc::setsockopt( self.socket.as_raw_fd(), level, @@ -375,7 +380,12 @@ impl Socket { } #[cfg(windows)] - pub unsafe fn set_socket_option(&self, level: i32, name: i32, value: &T) -> io::Result<()> { + pub unsafe fn set_socket_option( + &self, + level: i32, + name: i32, + value: &T, + ) -> io::Result<()> { syscall!( SOCKET, windows_sys::Win32::Networking::WinSock::setsockopt( diff --git a/compio-net/src/udp.rs b/compio-net/src/udp.rs index 7a28025a..33f39c2d 100644 --- a/compio-net/src/udp.rs +++ b/compio-net/src/udp.rs @@ -321,7 +321,7 @@ impl UdpSocket { /// # Safety /// /// The caller must ensure `T` is the correct type for `level` and `name`. - pub unsafe fn get_socket_option(&self, level: i32, name: i32) -> io::Result { + pub unsafe fn get_socket_option(&self, level: i32, name: i32) -> io::Result { self.inner.get_socket_option(level, name) } @@ -330,7 +330,12 @@ impl UdpSocket { /// # Safety /// /// The caller must ensure `T` is the correct type for `level` and `name`. - pub unsafe fn set_socket_option(&self, level: i32, name: i32, value: &T) -> io::Result<()> { + pub unsafe fn set_socket_option( + &self, + level: i32, + name: i32, + value: &T, + ) -> io::Result<()> { self.inner.set_socket_option(level, name, value) } }