Skip to content

Commit d4c1872

Browse files
committed
Added SO_PRIORITY socket option (#587)
1 parent 758a9e2 commit d4c1872

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/socket.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,35 @@ impl Socket {
996996
}
997997
}
998998

999+
/// Get value for the `SO_PRIORITY` option on this socket.
1000+
///
1001+
/// For more information about this option, see [`set_priority`].
1002+
///
1003+
/// [`set_priority`]: Socket::set_priority
1004+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "fuchsia"))]
1005+
pub fn priority(&self) -> io::Result<i32> {
1006+
unsafe {
1007+
getsockopt::<c_int>(self.as_raw(), sys::SOL_SOCKET, sys::SO_PRIORITY)
1008+
.map(|prio| prio as i32)
1009+
}
1010+
}
1011+
1012+
/// Set value for the `SO_PRIORITY` option on this socket.
1013+
///
1014+
/// Packets with a higher priority may be processed earlier depending on the selected device
1015+
/// queueing discipline.
1016+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "fuchsia"))]
1017+
pub fn set_priority(&self, priority: i32) -> io::Result<()> {
1018+
unsafe {
1019+
setsockopt(
1020+
self.as_raw(),
1021+
sys::SOL_SOCKET,
1022+
sys::SO_PRIORITY,
1023+
priority as c_int,
1024+
)
1025+
}
1026+
}
1027+
9991028
/// Get value for the `SO_RCVBUF` option on this socket.
10001029
///
10011030
/// For more information about this option, see [`set_recv_buffer_size`].

src/sys/unix.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ pub(crate) use libc::SO_LINGER;
206206
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
207207
#[cfg(any(target_os = "linux", target_os = "cygwin"))]
208208
pub(crate) use libc::SO_PASSCRED;
209+
#[cfg(any(target_os = "linux", target_os = "android", target_os = "fuchsia"))]
210+
pub(crate) use libc::SO_PRIORITY;
209211
pub(crate) use libc::{
210212
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
211213
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,

0 commit comments

Comments
 (0)