Skip to content

Commit

Permalink
Run rustfmt on everything
Browse files Browse the repository at this point in the history
Some files are not picked up by running cargo fmt, but
find src tests examples -type f -iname "*.rs" | xargs rustfmt
does the trick.
  • Loading branch information
Thomasdezeeuw committed Jul 26, 2023
1 parent 9a27f21 commit df992df
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! [portability guidelines]: ../struct.Poll.html#portability

mod tcp;
pub use self::tcp::{TcpListener, TcpSocket, TcpStream, TcpKeepalive};
pub use self::tcp::{TcpKeepalive, TcpListener, TcpSocket, TcpStream};

mod udp;
pub use self::udp::UdpSocket;
Expand Down
2 changes: 1 addition & 1 deletion src/net/tcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod listener;
pub use self::listener::TcpListener;

mod socket;
pub use self::socket::{TcpSocket, TcpKeepalive};
pub use self::socket::{TcpKeepalive, TcpSocket};

mod stream;
pub use self::stream::TcpStream;
30 changes: 11 additions & 19 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::net::{self, SocketAddr};
use std::os::unix::io::{AsRawFd, FromRawFd};
use std::time::Duration;

use crate::sys::unix::net::{new_socket, socket_addr, to_socket_addr};
use crate::net::TcpKeepalive;
use crate::sys::unix::net::{new_socket, socket_addr, to_socket_addr};

#[cfg(any(target_os = "openbsd", target_os = "netbsd", target_os = "haiku"))]
use libc::SO_KEEPALIVE as KEEPALIVE_TIME;
Expand Down Expand Up @@ -41,12 +41,8 @@ pub(crate) fn connect(socket: TcpSocket, addr: SocketAddr) -> io::Result<net::Tc
let (raw_addr, raw_addr_length) = socket_addr(&addr);

match syscall!(connect(socket, raw_addr.as_ptr(), raw_addr_length)) {
Err(err) if err.raw_os_error() != Some(libc::EINPROGRESS) => {
Err(err)
}
_ => {
Ok(unsafe { net::TcpStream::from_raw_fd(socket) })
}
Err(err) if err.raw_os_error() != Some(libc::EINPROGRESS) => Err(err),
_ => Ok(unsafe { net::TcpStream::from_raw_fd(socket) }),
}
}

Expand Down Expand Up @@ -151,7 +147,7 @@ pub(crate) fn set_linger(socket: TcpSocket, dur: Option<Duration>) -> io::Result
}

pub(crate) fn get_linger(socket: TcpSocket) -> io::Result<Option<Duration>> {
let mut val: libc::linger = unsafe { std::mem::zeroed() };
let mut val: libc::linger = unsafe { std::mem::zeroed() };
let mut len = mem::size_of::<libc::linger>() as libc::socklen_t;

syscall!(getsockopt(
Expand Down Expand Up @@ -268,13 +264,12 @@ pub(crate) fn set_keepalive_params(socket: TcpSocket, keepalive: TcpKeepalive) -
if let Some(dur) = keepalive.interval {
set_keepalive_interval(socket, dur)?;
}

if let Some(retries) = keepalive.retries {
set_keepalive_retries(socket, retries)?;
}
}


Ok(())
}

Expand Down Expand Up @@ -456,12 +451,9 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
// OSes inherit the non-blocking flag from the listener, so we just have to
// set `CLOEXEC`.
#[cfg(any(
all(
target_arch = "x86",
target_os = "android"
),
target_os = "ios",
target_os = "macos",
all(target_arch = "x86", target_os = "android"),
target_os = "ios",
target_os = "macos",
target_os = "solaris"
))]
let stream = {
Expand All @@ -473,11 +465,11 @@ pub fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream, Socket
.map(|socket| unsafe { net::TcpStream::from_raw_fd(socket) })
.and_then(|s| {
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFD, libc::FD_CLOEXEC))?;

// See https://github.com/tokio-rs/mio/issues/1450
#[cfg(all(target_arch = "x86",target_os = "android"))]
#[cfg(all(target_arch = "x86", target_os = "android"))]
syscall!(fcntl(s.as_raw_fd(), libc::F_SETFL, libc::O_NONBLOCK))?;

Ok(s)
})
}?;
Expand Down
9 changes: 3 additions & 6 deletions src/sys/unix/uds/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
target_os = "macos",
target_os = "netbsd",
target_os = "solaris",
all(
target_arch = "x86",
target_os = "android"
)
all(target_arch = "x86", target_os = "android")
))]
let socket = syscall!(accept(
listener.as_raw_fd(),
Expand All @@ -83,9 +80,9 @@ pub(crate) fn accept(listener: &net::UnixListener) -> io::Result<(UnixStream, So
syscall!(fcntl(socket, libc::F_SETFD, libc::FD_CLOEXEC))?;

// See https://github.com/tokio-rs/mio/issues/1450
#[cfg(all(target_arch = "x86",target_os = "android"))]
#[cfg(all(target_arch = "x86", target_os = "android"))]
syscall!(fcntl(socket, libc::F_SETFL, libc::O_NONBLOCK))?;

Ok(s)
});

Expand Down
8 changes: 4 additions & 4 deletions src/sys/windows/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::net::SocketAddr;
use std::sync::Once;

use winapi::ctypes::c_int;
use winapi::shared::inaddr::{in_addr_S_un, IN_ADDR};
use winapi::shared::in6addr::{in6_addr_u, IN6_ADDR};
use winapi::shared::ws2def::{AF_INET, AF_INET6, ADDRESS_FAMILY, SOCKADDR, SOCKADDR_IN};
use winapi::shared::ws2ipdef::{SOCKADDR_IN6_LH, SOCKADDR_IN6_LH_u};
use winapi::shared::inaddr::{in_addr_S_un, IN_ADDR};
use winapi::shared::ws2def::{ADDRESS_FAMILY, AF_INET, AF_INET6, SOCKADDR, SOCKADDR_IN};
use winapi::shared::ws2ipdef::{SOCKADDR_IN6_LH_u, SOCKADDR_IN6_LH};
use winapi::um::winsock2::{ioctlsocket, socket, FIONBIO, INVALID_SOCKET, SOCKET};

/// Initialise the network stack for Windows.
Expand Down Expand Up @@ -80,7 +80,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, c_int) {

let sockaddr = SocketAddrCRepr { v4: sockaddr_in };
(sockaddr, mem::size_of::<SOCKADDR_IN>() as c_int)
},
}
SocketAddr::V6(ref addr) => {
let sin6_addr = unsafe {
let mut u = mem::zeroed::<in6_addr_u>();
Expand Down

0 comments on commit df992df

Please sign in to comment.