-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net: add tos and set_tos methods to TCP and UDP sockets #4366
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
03a28ab
net: fix build error on master
taiki-e 3d1e1fd
net: add tos and set_tos methods to TCP and UDP sockets
taiki-e f550438
Merge remote-tracking branch 'origin/master' into taiki-e/net-sock-tos
taiki-e 68cd47a
fix doc cfg
taiki-e fdd5865
rename to_socket -> as_socket
taiki-e 713f4f0
Merge remote-tracking branch 'origin/master' into taiki-e/net-sock-tos
taiki-e b937408
Merge remote-tracking branch 'origin/master' into taiki-e/net-sock-tos
taiki-e File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1480,6 +1480,71 @@ impl UdpSocket { | |||||||||||||
self.io.set_ttl(ttl) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// Gets the value of the `IP_TOS` option for this socket. | ||||||||||||||
/// | ||||||||||||||
/// For more information about this option, see [`set_tos`]. | ||||||||||||||
/// | ||||||||||||||
/// **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`]: Self::set_tos | ||||||||||||||
// https://docs.rs/socket2/0.4.2/src/socket2/socket.rs.html#1178 | ||||||||||||||
#[cfg(not(any( | ||||||||||||||
target_os = "fuchsia", | ||||||||||||||
target_os = "redox", | ||||||||||||||
target_os = "solaris", | ||||||||||||||
target_os = "illumos", | ||||||||||||||
)))] | ||||||||||||||
#[cfg_attr( | ||||||||||||||
docsrs, | ||||||||||||||
doc(cfg(all( | ||||||||||||||
unix, | ||||||||||||||
not(any( | ||||||||||||||
target_os = "fuchsia", | ||||||||||||||
target_os = "redox", | ||||||||||||||
target_os = "solaris", | ||||||||||||||
target_os = "illumos", | ||||||||||||||
)) | ||||||||||||||
))) | ||||||||||||||
)] | ||||||||||||||
pub fn tos(&self) -> io::Result<u32> { | ||||||||||||||
self.to_socket().tos() | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
/// Sets the value for the `IP_TOS` option on this socket. | ||||||||||||||
/// | ||||||||||||||
/// This value sets the time-to-live 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.4.2/src/socket2/socket.rs.html#1178 | ||||||||||||||
#[cfg(not(any( | ||||||||||||||
target_os = "fuchsia", | ||||||||||||||
target_os = "redox", | ||||||||||||||
target_os = "solaris", | ||||||||||||||
target_os = "illumos", | ||||||||||||||
)))] | ||||||||||||||
#[cfg_attr( | ||||||||||||||
docsrs, | ||||||||||||||
doc(cfg(all( | ||||||||||||||
unix, | ||||||||||||||
not(any( | ||||||||||||||
target_os = "fuchsia", | ||||||||||||||
target_os = "redox", | ||||||||||||||
target_os = "solaris", | ||||||||||||||
target_os = "illumos", | ||||||||||||||
)) | ||||||||||||||
))) | ||||||||||||||
)] | ||||||||||||||
pub fn set_tos(&self, tos: u32) -> io::Result<()> { | ||||||||||||||
self.to_socket().set_tos(tos) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
fn to_socket(&self) -> socket2::SockRef<'_> { | ||||||||||||||
socket2::SockRef::from(self) | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like I commented on the other PR, it is more idiomatic to call it
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done in fdd5865 |
||||||||||||||
|
||||||||||||||
/// Executes an operation of the `IP_ADD_MEMBERSHIP` type. | ||||||||||||||
/// | ||||||||||||||
/// This function specifies a new multicast group for this socket to join. | ||||||||||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of these includes a
all(unix, ...)
and the other doesn't. Why?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I forgot to remove
all(unix, ...)
when I copied the doc cfg fromTcpSocket::reuseport
.