Skip to content

Commit f3c875b

Browse files
committed
changes from feedback
1 parent c005f3e commit f3c875b

File tree

1 file changed

+49
-22
lines changed

1 file changed

+49
-22
lines changed

src/sys/socket/sockopt.rs

+49-22
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Socket options as used by `setsockopt` and `getsockopt`.
2-
#[cfg(linux_android)]
2+
#[cfg(any(linux_android, target_os = "illumos"))]
33
use super::SetSockOpt;
44
use crate::sys::time::TimeVal;
5-
#[cfg(linux_android)]
5+
#[cfg(any(linux_android, target_os = "illumos"))]
66
use crate::{errno::Errno, Result};
77
use cfg_if::cfg_if;
88
use libc::{self, c_int, c_void, socklen_t};
@@ -11,7 +11,7 @@ use std::ffi::CString;
1111
use std::ffi::{CStr, OsStr, OsString};
1212
use std::mem::{self, MaybeUninit};
1313
use std::os::unix::ffi::OsStrExt;
14-
#[cfg(linux_android)]
14+
#[cfg(any(linux_android, target_os = "illumos"))]
1515
use std::os::unix::io::{AsFd, AsRawFd};
1616

1717
// Constants
@@ -987,25 +987,6 @@ sockopt_impl!(
987987
libc::SO_ACCEPTFILTER,
988988
libc::accept_filter_arg
989989
);
990-
#[cfg(target_os = "illumos")]
991-
sockopt_impl!(
992-
/// Attach a named filter to this socket to be able to
993-
/// defer when anough byte had been buffered by the kernel
994-
FilAttach,
995-
SetOnly,
996-
libc::SOL_FILTER,
997-
libc::FIL_ATTACH,
998-
SetOsString<'static>
999-
);
1000-
#[cfg(target_os = "illumos")]
1001-
sockopt_impl!(
1002-
/// Detach a socket filter previously attached with FIL_ATTACH
1003-
FilDetach,
1004-
SetOnly,
1005-
libc::SOL_FILTER,
1006-
libc::FIL_DETACH,
1007-
SetOsString<'static>
1008-
);
1009990
#[cfg(target_os = "linux")]
1010991
sockopt_impl!(
1011992
/// Set the mark for each packet sent through this socket (similar to the
@@ -1501,6 +1482,52 @@ impl SetSockOpt for TcpTlsRx {
15011482
}
15021483
}
15031484

1485+
#[cfg(target_os = "illumos")]
1486+
#[derive(Copy, Clone, Debug)]
1487+
/// Attach a named filter to this socket to be able to
1488+
/// defer when anough byte had been buffered by the kernel
1489+
pub struct FilAttach;
1490+
1491+
#[cfg(target_os = "illumos")]
1492+
impl<'a> SetSockOpt for FilAttach {
1493+
type Val = [u8; libc::FILNAME_MAX as usize];
1494+
1495+
fn set<F: AsFd>(&self, fd: &F, val: &[u8; libc::FILNAME_MAX as usize]) -> Result<()> {
1496+
unsafe {
1497+
let res = libc::setsockopt(
1498+
fd.as_fd().as_raw_fd(),
1499+
libc::SOL_FILTER,
1500+
libc::FIL_ATTACH,
1501+
val.as_ptr().cast(),
1502+
val.len() as libc::socklen_t,
1503+
);
1504+
Errno::result(res).map(drop)
1505+
}
1506+
}
1507+
}
1508+
1509+
#[cfg(target_os = "illumos")]
1510+
#[derive(Copy, Clone, Debug)]
1511+
/// Detach a socket filter previously attached with FIL_ATTACH
1512+
pub struct FilDetach;
1513+
1514+
#[cfg(target_os = "illumos")]
1515+
impl<'a> SetSockOpt for FilDetach {
1516+
type Val = [u8; libc::FILNAME_MAX as usize];
1517+
1518+
fn set<F: AsFd>(&self, fd: &F, val: &[u8; libc::FILNAME_MAX as usize]) -> Result<()> {
1519+
unsafe {
1520+
let res = libc::setsockopt(
1521+
fd.as_fd().as_raw_fd(),
1522+
libc::SOL_FILTER,
1523+
libc::FIL_DETACH,
1524+
val.as_ptr().cast(),
1525+
val.len() as libc::socklen_t,
1526+
);
1527+
Errno::result(res).map(drop)
1528+
}
1529+
}
1530+
}
15041531
/*
15051532
*
15061533
* ===== Accessor helpers =====

0 commit comments

Comments
 (0)