Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 139 additions & 10 deletions tokio/src/net/tcp/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,113 @@ impl TcpSocket {
self.inner.tcp_nodelay()
}

/// Gets the value of the `IPV6_TCLASS` option for this socket.
///
/// For more information about this option, see [`set_tclass_v6`].
///
/// [`set_tclass_v6`]: Self::set_tclass_v6
// https://docs.rs/socket2/0.6.1/src/socket2/sys/unix.rs.html#2541
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
#[cfg_attr(
docsrs,
doc(cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
)))
)]
pub fn tclass_v6(&self) -> io::Result<u32> {
self.inner.tclass_v6()
}

/// Sets the value for the `IPV6_TCLASS` option on this socket.
///
/// Specifies the traffic class field that is used in every packet
/// sent from this socket.
///
/// # Note
///
/// This may not have any effect on IPv4 sockets.
// https://docs.rs/socket2/0.6.1/src/socket2/sys/unix.rs.html#2566
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
#[cfg_attr(
docsrs,
doc(cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
)))
)]
pub fn set_tclass_v6(&self, tclass: u32) -> io::Result<()> {
self.inner.set_tclass_v6(tclass)
}

/// Gets the value of the `IP_TOS` option for this socket.
///
/// For more information about this option, see [`set_tos`].
/// For more information about this option, see [`set_tos_v4`].
///
/// **NOTE:** On Windows, `IP_TOS` is only supported on [Windows 8+ or
/// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options)
/// [`set_tos_v4`]: Self::set_tos_v4
// https://docs.rs/socket2/0.6.1/src/socket2/socket.rs.html#1585
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
)))]
#[cfg_attr(
docsrs,
doc(cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
))))
)]
pub fn tos_v4(&self) -> io::Result<u32> {
self.inner.tos_v4()
}

/// Deprecated. Use [`tos_v4()`] instead.
///
/// [`set_tos`]: Self::set_tos
// https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1464
/// [`tos_v4()`]: Self::tos_v4
#[deprecated(
note = "`tos` related methods have been renamed `tos_v4` since they are IPv4-specific."
)]
#[doc(hidden)]
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
Expand All @@ -516,17 +614,20 @@ impl TcpSocket {
))))
)]
pub fn tos(&self) -> io::Result<u32> {
self.inner.tos_v4()
self.tos_v4()
}

/// Sets the value for the `IP_TOS` option on this socket.
///
/// This value sets the type-of-service field that is used in every packet
/// sent from this socket.
///
/// **NOTE:** On Windows, `IP_TOS` is only supported on [Windows 8+ or
/// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options)
Comment thread
ADD-SP marked this conversation as resolved.
// https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1446
/// # Note
///
/// - This may not have any effect on IPv6 sockets.
/// - On Windows, `IP_TOS` is only supported on [Windows 8+ or
/// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options)
// https://docs.rs/socket2/0.6.1/src/socket2/socket.rs.html#1566
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
Expand All @@ -544,10 +645,38 @@ impl TcpSocket {
target_os = "haiku"
))))
)]
pub fn set_tos(&self, tos: u32) -> io::Result<()> {
pub fn set_tos_v4(&self, tos: u32) -> io::Result<()> {
self.inner.set_tos_v4(tos)
}

/// Deprecated. Use [`set_tos_v4()`] instead.
///
/// [`set_tos_v4()`]: Self::set_tos_v4
#[deprecated(
note = "`tos` related methods have been renamed `tos_v4` since they are IPv4-specific."
)]
#[doc(hidden)]
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
)))]
#[cfg_attr(
docsrs,
doc(cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
))))
)]
pub fn set_tos(&self, tos: u32) -> io::Result<()> {
self.set_tos_v4(tos)
}

/// Gets the value for the `SO_BINDTODEVICE` option on this socket
///
/// This value gets the socket binded device's interface name.
Expand Down
155 changes: 142 additions & 13 deletions tokio/src/net/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ impl UdpSocket {
///
/// # Note
///
/// This may not have any affect on IPv6 sockets.
/// This may not have any effect on IPv6 sockets.
pub fn set_multicast_loop_v4(&self, on: bool) -> io::Result<()> {
self.io.set_multicast_loop_v4(on)
}
Expand All @@ -1930,7 +1930,7 @@ impl UdpSocket {
///
/// # Note
///
/// This may not have any affect on IPv6 sockets.
/// This may not have any effect on IPv6 sockets.
pub fn set_multicast_ttl_v4(&self, ttl: u32) -> io::Result<()> {
self.io.set_multicast_ttl_v4(ttl)
}
Expand All @@ -1950,11 +1950,84 @@ impl UdpSocket {
///
/// # Note
///
/// This may not have any affect on IPv4 sockets.
/// This may not have any effect on IPv4 sockets.
pub fn set_multicast_loop_v6(&self, on: bool) -> io::Result<()> {
self.io.set_multicast_loop_v6(on)
}

/// Gets the value of the `IPV6_TCLASS` option for this socket.
///
/// For more information about this option, see [`set_tclass_v6`].
///
/// [`set_tclass_v6`]: Self::set_tclass_v6
// https://docs.rs/socket2/0.6.1/src/socket2/sys/unix.rs.html#2541
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
#[cfg_attr(
docsrs,
doc(cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
)))
)]
pub fn tclass_v6(&self) -> io::Result<u32> {
self.as_socket().tclass_v6()
}

/// Sets the value for the `IPV6_TCLASS` option on this socket.
///
/// Specifies the traffic class field that is used in every packet
/// sent from this socket.
///
/// # Note
///
/// This may not have any effect on IPv4 sockets.
// https://docs.rs/socket2/0.6.1/src/socket2/sys/unix.rs.html#2566
Comment thread
jtojnar marked this conversation as resolved.
#[cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
))]
#[cfg_attr(
docsrs,
doc(cfg(any(
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "linux",
target_os = "macos",
target_os = "netbsd",
target_os = "openbsd",
target_os = "cygwin",
)))
)]
pub fn set_tclass_v6(&self, tclass: u32) -> io::Result<()> {
self.as_socket().set_tclass_v6(tclass)
}

/// Gets the value of the `IP_TTL` option for this socket.
///
/// For more information about this option, see [`set_ttl`].
Expand Down Expand Up @@ -2002,13 +2075,38 @@ impl UdpSocket {

/// Gets the value of the `IP_TOS` option for this socket.
///
/// For more information about this option, see [`set_tos`].
/// For more information about this option, see [`set_tos_v4`].
///
/// **NOTE:** On Windows, `IP_TOS` is only supported on [Windows 8+ or
/// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options)
Comment thread
ADD-SP marked this conversation as resolved.
/// [`set_tos_v4`]: Self::set_tos_v4
// https://docs.rs/socket2/0.6.1/src/socket2/socket.rs.html#1585
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
)))]
#[cfg_attr(
docsrs,
doc(cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
))))
)]
pub fn tos_v4(&self) -> io::Result<u32> {
self.as_socket().tos_v4()
}

/// Deprecated. Use [`tos_v4()`] instead.
///
/// [`set_tos`]: Self::set_tos
// https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1464
/// [`tos_v4()`]: Self::tos_v4
#[deprecated(
note = "`tos` related methods have been renamed `tos_v4` since they are IPv4-specific."
)]
#[doc(hidden)]
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
Expand All @@ -2027,17 +2125,20 @@ impl UdpSocket {
))))
)]
pub fn tos(&self) -> io::Result<u32> {
self.as_socket().tos_v4()
self.tos_v4()
}

/// Sets the value for the `IP_TOS` option on this socket.
///
/// This value sets the type-of-service field that is used in every packet
/// sent from this socket.
///
/// **NOTE:** On Windows, `IP_TOS` is only supported on [Windows 8+ or
/// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options)
// https://docs.rs/socket2/0.5.3/src/socket2/socket.rs.html#1446
/// # Note
///
/// - This may not have any effect on IPv6 sockets.
/// - On Windows, `IP_TOS` is only supported on [Windows 8+ or
/// Windows Server 2012+.](https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options)
// https://docs.rs/socket2/0.6.1/src/socket2/socket.rs.html#1566
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
Expand All @@ -2055,10 +2156,38 @@ impl UdpSocket {
target_os = "haiku"
))))
)]
pub fn set_tos(&self, tos: u32) -> io::Result<()> {
pub fn set_tos_v4(&self, tos: u32) -> io::Result<()> {
self.as_socket().set_tos_v4(tos)
}

/// Deprecated. Use [`set_tos_v4()`] instead.
///
/// [`set_tos_v4()`]: Self::set_tos_v4
#[deprecated(
note = "`tos` related methods have been renamed `tos_v4` since they are IPv4-specific."
)]
#[doc(hidden)]
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
)))]
#[cfg_attr(
docsrs,
doc(cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku"
))))
)]
pub fn set_tos(&self, tos: u32) -> io::Result<()> {
self.set_tos_v4(tos)
}

/// Gets the value for the `SO_BINDTODEVICE` option on this socket
///
/// This value gets the socket-bound device's interface name.
Expand Down
Loading