Skip to content

Commit 148f3ac

Browse files
committed
chore(net): add type constraint for get/set_socket_option
1 parent b1ed765 commit 148f3ac

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

compio-net/src/socket.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl Socket {
324324
}
325325

326326
#[cfg(unix)]
327-
pub unsafe fn get_socket_option<T>(&self, level: i32, name: i32) -> io::Result<T> {
327+
pub unsafe fn get_socket_option<T: Copy>(&self, level: i32, name: i32) -> io::Result<T> {
328328
let mut value: MaybeUninit<T> = MaybeUninit::uninit();
329329
let mut len = size_of::<T>() as libc::socklen_t;
330330
syscall!(libc::getsockopt(
@@ -342,7 +342,7 @@ impl Socket {
342342
}
343343

344344
#[cfg(windows)]
345-
pub unsafe fn get_socket_option<T>(&self, level: i32, name: i32) -> io::Result<T> {
345+
pub unsafe fn get_socket_option<T: Copy>(&self, level: i32, name: i32) -> io::Result<T> {
346346
let mut value: MaybeUninit<T> = MaybeUninit::uninit();
347347
let mut len = size_of::<T>() as i32;
348348
syscall!(
@@ -363,7 +363,12 @@ impl Socket {
363363
}
364364

365365
#[cfg(unix)]
366-
pub unsafe fn set_socket_option<T>(&self, level: i32, name: i32, value: &T) -> io::Result<()> {
366+
pub unsafe fn set_socket_option<T: Copy>(
367+
&self,
368+
level: i32,
369+
name: i32,
370+
value: &T,
371+
) -> io::Result<()> {
367372
syscall!(libc::setsockopt(
368373
self.socket.as_raw_fd(),
369374
level,
@@ -375,7 +380,12 @@ impl Socket {
375380
}
376381

377382
#[cfg(windows)]
378-
pub unsafe fn set_socket_option<T>(&self, level: i32, name: i32, value: &T) -> io::Result<()> {
383+
pub unsafe fn set_socket_option<T: Copy>(
384+
&self,
385+
level: i32,
386+
name: i32,
387+
value: &T,
388+
) -> io::Result<()> {
379389
syscall!(
380390
SOCKET,
381391
windows_sys::Win32::Networking::WinSock::setsockopt(

compio-net/src/udp.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl UdpSocket {
321321
/// # Safety
322322
///
323323
/// The caller must ensure `T` is the correct type for `level` and `name`.
324-
pub unsafe fn get_socket_option<T>(&self, level: i32, name: i32) -> io::Result<T> {
324+
pub unsafe fn get_socket_option<T: Copy>(&self, level: i32, name: i32) -> io::Result<T> {
325325
self.inner.get_socket_option(level, name)
326326
}
327327

@@ -330,7 +330,12 @@ impl UdpSocket {
330330
/// # Safety
331331
///
332332
/// The caller must ensure `T` is the correct type for `level` and `name`.
333-
pub unsafe fn set_socket_option<T>(&self, level: i32, name: i32, value: &T) -> io::Result<()> {
333+
pub unsafe fn set_socket_option<T: Copy>(
334+
&self,
335+
level: i32,
336+
name: i32,
337+
value: &T,
338+
) -> io::Result<()> {
334339
self.inner.set_socket_option(level, name, value)
335340
}
336341
}

0 commit comments

Comments
 (0)