1
1
//! Socket options as used by `setsockopt` and `getsockopt`.
2
- #[ cfg( linux_android) ]
2
+ #[ cfg( any ( linux_android, target_os = "illumos" ) ) ]
3
3
use super :: SetSockOpt ;
4
4
use crate :: sys:: time:: TimeVal ;
5
- #[ cfg( linux_android) ]
5
+ #[ cfg( any ( linux_android, target_os = "illumos" ) ) ]
6
6
use crate :: { errno:: Errno , Result } ;
7
7
use cfg_if:: cfg_if;
8
8
use libc:: { self , c_int, c_void, socklen_t} ;
@@ -11,7 +11,7 @@ use std::ffi::CString;
11
11
use std:: ffi:: { CStr , OsStr , OsString } ;
12
12
use std:: mem:: { self , MaybeUninit } ;
13
13
use std:: os:: unix:: ffi:: OsStrExt ;
14
- #[ cfg( linux_android) ]
14
+ #[ cfg( any ( linux_android, target_os = "illumos" ) ) ]
15
15
use std:: os:: unix:: io:: { AsFd , AsRawFd } ;
16
16
17
17
// Constants
@@ -1483,6 +1483,58 @@ impl SetSockOpt for TcpTlsRx {
1483
1483
}
1484
1484
}
1485
1485
1486
+ #[ cfg( target_os = "illumos" ) ]
1487
+ #[ derive( Copy , Clone , Debug ) ]
1488
+ /// Attach a named filter to this socket to be able to
1489
+ /// defer when anough byte had been buffered by the kernel
1490
+ pub struct FilterAttach ;
1491
+
1492
+ #[ cfg( target_os = "illumos" ) ]
1493
+ impl SetSockOpt for FilterAttach {
1494
+ type Val = OsStr ;
1495
+
1496
+ fn set < F : AsFd > ( & self , fd : & F , val : & Self :: Val ) -> Result < ( ) > {
1497
+ if val. len ( ) > libc:: FILNAME_MAX as usize {
1498
+ return Err ( Errno :: EINVAL ) ;
1499
+ }
1500
+ unsafe {
1501
+ let res = libc:: setsockopt (
1502
+ fd. as_fd ( ) . as_raw_fd ( ) ,
1503
+ libc:: SOL_FILTER ,
1504
+ libc:: FIL_ATTACH ,
1505
+ val. as_bytes ( ) . as_ptr ( ) . cast ( ) ,
1506
+ val. len ( ) as libc:: socklen_t ,
1507
+ ) ;
1508
+ Errno :: result ( res) . map ( drop)
1509
+ }
1510
+ }
1511
+ }
1512
+
1513
+ #[ cfg( target_os = "illumos" ) ]
1514
+ #[ derive( Copy , Clone , Debug ) ]
1515
+ /// Detach a socket filter previously attached with FIL_ATTACH
1516
+ pub struct FilterDetach ;
1517
+
1518
+ #[ cfg( target_os = "illumos" ) ]
1519
+ impl SetSockOpt for FilterDetach {
1520
+ type Val = OsStr ;
1521
+
1522
+ fn set < F : AsFd > ( & self , fd : & F , val : & Self :: Val ) -> Result < ( ) > {
1523
+ if val. len ( ) > libc:: FILNAME_MAX as usize {
1524
+ return Err ( Errno :: EINVAL ) ;
1525
+ }
1526
+ unsafe {
1527
+ let res = libc:: setsockopt (
1528
+ fd. as_fd ( ) . as_raw_fd ( ) ,
1529
+ libc:: SOL_FILTER ,
1530
+ libc:: FIL_DETACH ,
1531
+ val. as_bytes ( ) . as_ptr ( ) . cast ( ) ,
1532
+ val. len ( ) as libc:: socklen_t ,
1533
+ ) ;
1534
+ Errno :: result ( res) . map ( drop)
1535
+ }
1536
+ }
1537
+ }
1486
1538
/*
1487
1539
*
1488
1540
* ===== Accessor helpers =====
@@ -1800,7 +1852,7 @@ pub struct SetOsString<'a> {
1800
1852
val : & ' a OsStr ,
1801
1853
}
1802
1854
1803
- #[ cfg( any( target_os = "freebsd" , linux_android) ) ]
1855
+ #[ cfg( any( target_os = "freebsd" , linux_android, target_os = "illumos" ) ) ]
1804
1856
impl < ' a > Set < ' a , OsString > for SetOsString < ' a > {
1805
1857
fn new ( val : & OsString ) -> SetOsString {
1806
1858
SetOsString {
0 commit comments