Skip to content
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

Issue: #523 #524

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(https://github.com/rust-lang/socket2/pull/448).
* Added `Socket::protocol` for Windows (using `WSAPROTOCOL_INFOW`)
(https://github.com/rust-lang/socket2/pull/470).
* `From<SocketAddrV{4,6}>` for `SockAddr ` nows sets `ss_len` on platforms that
* `From<SocketAddrV{4,6}>` for `SockAddr ` now sets `ss_len` on platforms that
have the fields (most BSDs)
(https://github.com/rust-lang/socket2/pull/469).
* Change Windows to use `ADDRESS_FAMILY` for `sa_family_t`, this shouldn't
Expand Down Expand Up @@ -90,7 +90,7 @@

## Fixed

* Generatation of documentation on docs.rs
* Generation of documentation on docs.rs
(https://github.com/rust-lang/socket2/pull/398).

# 0.5.0
Expand Down Expand Up @@ -204,7 +204,7 @@ This release was broken for Windows.

* Reverted back to the `winapi` dependency as switch to `windows-sys` was a
breaking change (https://github.com/rust-lang/socket2/pull/340).
Note that we'll will switch to `windows-sys` in v0.5 .
Note that we'll switch to `windows-sys` in v0.5 .
* Disable RECVTOS on OpenBSD
(https://github.com/rust-lang/socket2/pull/307).
* Derive Clone for SockAddr
Expand Down Expand Up @@ -360,7 +360,7 @@ This release was broken for Windows.
* `Protocol::tcp` => `Protocol::TCP`.
* `Protocol::udp` => `Protocol::UDP`.
* **BREAKING:** Changed the signature of `Socket::recv`, `Socket::recv_vectored`
and related methods to accept unitialised buffers. The `Read` implementation
and related methods to accept uninitialized buffers. The `Read` implementation
can be used to read into initialised buffers.
* **BREAKING:** Renamed `SockAddr::as_std` to `as_socket`.
* **BREAKING:** Renamed `SockAddr::as_inet` to `as_socket_ipv4`.
Expand All @@ -374,7 +374,7 @@ This release was broken for Windows.
* Split the `impl` block for the `Socket` type to create groupings for setting
and getting different level socket options using
`setsockopt(2)`/`getsockopt(2)`.
* Updated `winapi` depdency to version 0.3.9 and dropped unused features.
* Updated `winapi` dependency to version 0.3.9 and dropped unused features.

## Removed

Expand All @@ -389,17 +389,17 @@ This release was broken for Windows.
* `Socket::into_unix_listener` => `UnixListener::from(socket)`.
* `Socket::into_unix_datagram` => `UnixDatagram::from(socket)`.
* Removed `cfg-if` dependency.
* Remove `redox_syscall` depdency.
* Remove `redox_syscall` dependency.

## Fixes

* Fixes the Andoid, Fuchsia, Haiku, iOS, illumos, NetBSD and Redox (nightly
* Fixes the Android, Fuchsia, Haiku, iOS, illumos, NetBSD and Redox (nightly
only) targets.
* Correctly call `recv_from` in `Socket::recv_from_with_flags` (called `recv`
previously).
* Correctly call `send_to` in `Socket::send_to_with_flags` (called `recv`
previously).
* Use correct inmutable references in `Socket::send_with_flags` and
* Use correct immutable references in `Socket::send_with_flags` and
`Socket::send_out_of_band`.
* Use `IPPROTO_IPV6` in `Socket::join_multicast_v6` on Windows.
* Use `c_int` instead of `i32` where appropriate.
Expand All @@ -426,4 +426,4 @@ This release was broken for Windows.
# 0.3.16

* Don't assume the memory layout of `std::net::SocketAddr`.
* Other changes omited
* Other changes omitted
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ a collection of system calls for creating and using the socket, e.g.
for getting and setting socket options on various levels, e.g. `SOL_SOCKET`,
where each block contains a single level. The methods in these block are sorted
based on the option name, e.g. `IP_ADD_MEMBERSHIP` rather than
`join_multicast_v4`. Finally the last block contains platforms specific methods
`join_multicast_v4`. Finally, the last block contains platforms specific methods
such as `Socket::freebind` which is (at the time of writing) only available on
Android, Linux and Fuchsia, which is defined in the `src/sys/*.rs` files.

Expand All @@ -59,7 +59,7 @@ Other types are mostly defined in `src/lib.rs`, except for `SockAddr` and

Testing Socket2 is as simple as running `cargo test --all-features`.

However Socket2 supports a good number of OSs and features. If you want to
However, Socket2 supports a good number of OSs and features. If you want to
test/check all those combinations it's easier to use the [Makefile]. Using `make
test_all` it will check all supported OS targets and all combinations of
supported features. Note that this requires [cargo-hack] and various rustup
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub use socket::InterfaceIndexOrAddress;
///
/// This is a newtype wrapper around an integer which provides a nicer API in
/// addition to an injection point for documentation. Convenience constants such
/// as [`Domain::IPV4`], [`Domain::IPV6`], etc, are provided to avoid reaching
/// as [`Domain::IPV4`], [`Domain::IPV6`], etc., are provided to avoid reaching
/// into libc for various constants.
///
/// This type is freely interconvertible with C's `int` type, however, if a raw
Expand Down Expand Up @@ -243,7 +243,7 @@ impl From<Domain> for c_int {
///
/// This is a newtype wrapper around an integer which provides a nicer API in
/// addition to an injection point for documentation. Convenience constants such
/// as [`Type::STREAM`], [`Type::DGRAM`], etc, are provided to avoid reaching
/// as [`Type::STREAM`], [`Type::DGRAM`], etc., are provided to avoid reaching
/// into libc for various constants.
///
/// This type is freely interconvertible with C's `int` type, however, if a raw
Expand Down
24 changes: 12 additions & 12 deletions src/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl SockAddr {
/// let mut addr_storage: libc::sockaddr_storage = unsafe { mem::zeroed() };
/// let mut len = mem::size_of_val(&addr_storage) as libc::socklen_t;
///
/// // The `getsockname(2)` system call will intiliase `storage` for
/// // The `getsockname(2)` system call will initialise `storage` for
/// // us, setting `len` to the correct length.
/// let res = unsafe {
/// libc::getsockname(
Expand Down Expand Up @@ -105,7 +105,7 @@ impl SockAddr {
/// // Initialise a `SocketAddr` byte calling `getsockname(2)`.
/// let (_, address) = unsafe {
/// SockAddr::try_init(|addr_storage, len| {
/// // The `getsockname(2)` system call will intiliase `storage` for
/// // The `getsockname(2)` system call will initialise `storage` for
/// // us, setting `len` to the correct length.
/// if libc::getsockname(socket.as_raw_fd(), addr_storage.cast(), len) == -1 {
/// Err(io::Error::last_os_error())
Expand Down Expand Up @@ -183,7 +183,7 @@ impl SockAddr {
ptr::addr_of!(self.storage).cast()
}

/// Retuns the address as the storage.
/// Returns the address as the storage.
pub const fn as_storage(self) -> sockaddr_storage {
self.storage
}
Expand Down Expand Up @@ -258,7 +258,7 @@ impl SockAddr {
/// Returns the initialised storage bytes.
fn as_bytes(&self) -> &[u8] {
// SAFETY: `self.storage` is a C struct which can always be treated a
// slice of bytes. Furthermore, we ensure we don't read any unitialised
// slice of bytes. Furthermore, we ensure we don't read any uninitialized
// bytes by using `self.len`.
unsafe { std::slice::from_raw_parts(self.as_ptr().cast(), self.len as usize) }
}
Expand Down Expand Up @@ -550,18 +550,18 @@ mod tests {

#[allow(clippy::eq_op)] // allow a0 == a0 check
fn test_eq(a0: SockAddr, a1: SockAddr, b: SockAddr) {
assert!(a0 == a0);
assert!(a0 == a1);
assert!(a1 == a0);
assert!(a0 != b);
assert!(b != a0);
assert_eq!(a0, a0);
assert_eq!(a0, a1);
assert_eq!(a1, a0);
assert_ne!(a0, b);
assert_ne!(b, a0);
}

fn test_hash(a0: SockAddr, a1: SockAddr, b: SockAddr) {
assert!(calculate_hash(&a0) == calculate_hash(&a0));
assert!(calculate_hash(&a0) == calculate_hash(&a1));
assert_eq!(calculate_hash(&a0), calculate_hash(&a0));
assert_eq!(calculate_hash(&a0), calculate_hash(&a1));
// technically unequal values can have the same hash, in this case x != z and both have different hashes
assert!(calculate_hash(&a0) != calculate_hash(&b));
assert_ne!(calculate_hash(&a0), calculate_hash(&b));
}

fn calculate_hash(x: &SockAddr) -> u64 {
Expand Down
22 changes: 11 additions & 11 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl Socket {
// memory unsafe, so it's not desired but never memory unsafe or
// causes UB.
//
// However there is one exception. We use `TcpStream` to
// However, there is one exception. We use `TcpStream` to
// represent the `Socket` internally (see `Inner` type),
// `TcpStream` has a layout optimisation that doesn't allow for
// negative file descriptors (as those are always invalid).
Expand Down Expand Up @@ -206,7 +206,7 @@ impl Socket {
sys::connect(self.as_raw(), address)
}

/// Initiate a connection on this socket to the specified address, only
/// Initiate a connection on this socket to the specified address,
/// only waiting for a certain period of time for the connection to be
/// established.
///
Expand Down Expand Up @@ -408,7 +408,7 @@ impl Socket {
///
/// Normally casting a `&mut [u8]` to `&mut [MaybeUninit<u8>]` would be
/// unsound, as that allows us to write uninitialised bytes to the buffer.
/// However this implementation promises to not write uninitialised bytes to
/// However, this implementation promises to not write uninitialised bytes to
/// the `buf`fer and passes it directly to `recv(2)` system call. This
/// promise ensures that this function can be called using a `buf`fer of
/// type `&mut [u8]`.
Expand Down Expand Up @@ -461,7 +461,7 @@ impl Socket {
/// # Safety
///
/// Normally casting a `IoSliceMut` to `MaybeUninitSlice` would be unsound,
/// as that allows us to write uninitialised bytes to the buffer. However
/// as that allows us to write uninitialised bytes to the buffer. However,
/// this implementation promises to not write uninitialised bytes to the
/// `bufs` and passes it directly to `recvmsg(2)` system call. This promise
/// ensures that this function can be called using `bufs` of type `&mut
Expand Down Expand Up @@ -500,7 +500,7 @@ impl Socket {
sys::recv_vectored(self.as_raw(), bufs, flags)
}

/// Receives data on the socket from the remote adress to which it is
/// Receives data on the socket from the remote address to which it is
/// connected, without removing that data from the queue. On success,
/// returns the number of bytes peeked.
///
Expand Down Expand Up @@ -602,7 +602,7 @@ impl Socket {
/// # Note: Datagram Sockets
/// For datagram sockets, the behavior of this method when `buf` is smaller than
/// the datagram at the head of the receive queue differs between Windows and
/// Unix-like platforms (Linux, macOS, BSDs, etc: colloquially termed "*nix").
/// Unix-like platforms (Linux, macOS, BSDs, etc.: colloquially termed "*nix").
///
/// On *nix platforms, the datagram is truncated to the length of `buf`.
///
Expand Down Expand Up @@ -927,7 +927,7 @@ impl Socket {
/// On most OSs the duration only has a precision of seconds and will be
/// silently truncated.
///
/// On Apple platforms (e.g. macOS, iOS, etc) this uses `SO_LINGER_SEC`.
/// On Apple platforms (e.g. macOS, iOS, etc.) this uses `SO_LINGER_SEC`.
pub fn set_linger(&self, linger: Option<Duration>) -> io::Result<()> {
let linger = into_linger(linger);
unsafe { setsockopt(self.as_raw(), sys::SOL_SOCKET, sys::SO_LINGER, linger) }
Expand Down Expand Up @@ -1512,7 +1512,7 @@ impl Socket {
/// Set the value of the `IP_MULTICAST_LOOP` option for this socket.
///
/// If enabled, multicast packets will be looped back to the local socket.
/// Note that this may not have any affect on IPv6 sockets.
/// Note that this may not have any effect on IPv6 sockets.
pub fn set_multicast_loop_v4(&self, loop_v4: bool) -> io::Result<()> {
unsafe {
setsockopt(
Expand Down Expand Up @@ -1542,7 +1542,7 @@ impl Socket {
/// this socket. The default value is 1 which means that multicast packets
/// don't leave the local network unless explicitly requested.
///
/// Note that this may not have any affect on IPv6 sockets.
/// Note that this may not have any effect on IPv6 sockets.
pub fn set_multicast_ttl_v4(&self, ttl: u32) -> io::Result<()> {
unsafe {
setsockopt(
Expand Down Expand Up @@ -1878,7 +1878,7 @@ impl Socket {
/// Set the value of the `IPV6_MULTICAST_LOOP` option for this socket.
///
/// Controls whether this socket sees the multicast packets it sends itself.
/// Note that this may not have any affect on IPv4 sockets.
/// Note that this may not have any effect on IPv4 sockets.
pub fn set_multicast_loop_v6(&self, loop_v6: bool) -> io::Result<()> {
unsafe {
setsockopt(
Expand Down Expand Up @@ -2219,7 +2219,7 @@ impl Read for Socket {
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
// Safety: both `IoSliceMut` and `MaybeUninitSlice` promise to have the
// same layout, that of `iovec`/`WSABUF`. Furthermore, `recv_vectored`
// promises to not write unitialised bytes to the `bufs` and pass it
// promises to not write uninitialized bytes to the `bufs` and pass it
// directly to the `recvmsg` system call, so this is safe.
let bufs = unsafe { &mut *(bufs as *mut [IoSliceMut<'_>] as *mut [MaybeUninitSlice<'_>]) };
self.recv_vectored(bufs).map(|(n, _)| n)
Expand Down
Loading
Loading