Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-anssi committed Apr 11, 2023
1 parent c5245f7 commit 47c5a44
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 35 deletions.
8 changes: 6 additions & 2 deletions src/bin/diode-send-file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ fn main() {
.get_one::<String>("to_unix")
.map(|s| path::PathBuf::from_str(s).expect("to_unix must point to a valid path"));
let buffer_size = *args.get_one::<usize>("buffer_size").expect("default");
let files = args.get_many("file").expect("required").cloned().collect();
let files = args
.get_many("file")
.expect("required")
.cloned()
.collect::<Vec<_>>();

let diode = if let Some(to_tcp) = to_tcp {
file::DiodeSend::Tcp(to_tcp)
Expand All @@ -57,7 +61,7 @@ fn main() {

init_logger();

if let Err(e) = file::send::send_files(config, files) {
if let Err(e) = file::send::send_files(&config, &files) {
log::error!("{e}");
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/file/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ fn receive_unix_loop<'a>(
"new Unix client ({}) connected",
client_addr
.as_pathname()
.map(|p| p.display().to_string())
.unwrap_or("unknown".to_string())
.map_or("unknown".to_string(), |p| p.display().to_string())
);
if let Err(e) = client.shutdown(std::net::Shutdown::Write) {
log::warn!("failed to shutdown Unix client write: {e}");
Expand Down
8 changes: 4 additions & 4 deletions src/file/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use std::{
};

pub fn send_files(
config: file::Config<file::DiodeSend>,
files: Vec<String>,
config: &file::Config<file::DiodeSend>,
files: &[String],
) -> Result<(), file::Error> {
for file in &files {
let total = send_file(&config, file)?;
for file in files {
let total = send_file(config, file)?;
log::info!("file send, {total} bytes sent");
}
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ pub fn object_transmission_information(
let data_mtu: u16 =
RAPTORQ_ALIGNMENT * ((mtu - PACKET_HEADER_SIZE - RAPTORQ_HEADER_SIZE) / RAPTORQ_ALIGNMENT);

let nb_encoding_packets = logical_block_size / data_mtu as u64;
let nb_encoding_packets = logical_block_size / u64::from(data_mtu);

let encoding_block_size = data_mtu as u64 * nb_encoding_packets;
let encoding_block_size = u64::from(data_mtu) * nb_encoding_packets;

let data_mtu = (encoding_block_size / nb_encoding_packets) as u16;

Expand All @@ -180,12 +180,12 @@ pub fn packet_size(oti: &raptorq::ObjectTransmissionInformation) -> u16 {
}

pub fn nb_encoding_packets(oti: &raptorq::ObjectTransmissionInformation) -> u64 {
oti.transfer_length() / data_mtu(oti) as u64
oti.transfer_length() / u64::from(data_mtu(oti))
}

pub fn nb_repair_packets(
oti: &raptorq::ObjectTransmissionInformation,
repair_block_size: u32,
) -> u32 {
repair_block_size / data_mtu(oti) as u32
repair_block_size / u32::from(data_mtu(oti))
}
4 changes: 2 additions & 2 deletions src/receive/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
pub(crate) fn start<C, F, E>(
receiver: &receive::Receiver<F>,
client_id: protocol::ClientId,
recvq: crossbeam_channel::Receiver<protocol::Message>,
recvq: &crossbeam_channel::Receiver<protocol::Message>,
) -> Result<(), receive::Error>
where
C: Write + AsRawFd,
Expand All @@ -16,7 +16,7 @@ where
{
log::info!("client {client_id:x}: starting transfer");

let client = (receiver.new_client)().map_err(|e| e.into())?;
let client = (receiver.new_client)().map_err(Into::into)?;

let sock_buffer_size = sock_utils::get_socket_send_buffer_size(&client)?;
if (sock_buffer_size as usize) < 2 * receiver.to_buffer_size {
Expand Down
2 changes: 1 addition & 1 deletion src/receive/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
receiver.multiplex_control.acquire();
log::debug!("multiplex access acquired");

let client_res = client::start(receiver, client_id, recvq);
let client_res = client::start(receiver, client_id, &recvq);

receiver.multiplex_control.release();

Expand Down
4 changes: 2 additions & 2 deletions src/receive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ impl Config {
let nb_encoding_packets = protocol::nb_encoding_packets(&oti);
let nb_repair_packets = protocol::nb_repair_packets(&oti, self.repair_block_size);

self.encoding_block_size = nb_encoding_packets * packet_size as u64;
self.repair_block_size = nb_repair_packets * packet_size as u32;
self.encoding_block_size = nb_encoding_packets * u64::from(packet_size);
self.repair_block_size = nb_repair_packets * u32::from(packet_size);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/receive/reblock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) fn start<F>(receiver: &receive::Receiver<F>) -> Result<(), receive::E
Ok(packet) => packet,
};

for packet in packets.into_iter() {
for packet in packets {
let payload_id = packet.payload_id();
let message_block_id = payload_id.source_block_number();

Expand Down
2 changes: 1 addition & 1 deletion src/receive/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn start<F>(receiver: &receive::Receiver<F>) -> Result<(), receive::E
let sock_buffer_size = sock_utils::get_socket_recv_buffer_size(&socket)?;
log::info!("UDP socket receive buffer size set to {sock_buffer_size}");
if (sock_buffer_size as u64)
< 2 * (receiver.config.encoding_block_size + receiver.config.repair_block_size as u64)
< 2 * (receiver.config.encoding_block_size + u64::from(receiver.config.repair_block_size))
{
log::warn!("UDP socket recv buffer may be too small to achieve optimal performances");
log::warn!("Please review the kernel parameters using sysctl");
Expand Down
2 changes: 1 addition & 1 deletion src/send/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn start<C>(sender: &send::Sender<C>) -> Result<(), send::Error> {

let sbep = raptorq::SourceBlockEncodingPlan::generate(
(sender.object_transmission_info.transfer_length()
/ sender.object_transmission_info.symbol_size() as u64) as u16,
/ u64::from(sender.object_transmission_info.symbol_size())) as u16,
);

loop {
Expand Down
4 changes: 2 additions & 2 deletions src/send/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ impl Config {
let nb_encoding_packets = protocol::nb_encoding_packets(&oti);
let nb_repair_packets = protocol::nb_repair_packets(&oti, self.repair_block_size);

self.encoding_block_size = nb_encoding_packets * packet_size as u64;
self.repair_block_size = nb_repair_packets * packet_size as u32;
self.encoding_block_size = nb_encoding_packets * u64::from(packet_size);
self.repair_block_size = nb_repair_packets * u32::from(packet_size);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/send/udp_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) fn start<C>(sender: &send::Sender<C>) -> Result<(), send::Error> {
let sock_buffer_size = sock_utils::get_socket_send_buffer_size(&socket)?;
log::info!("UDP socket send buffer size set to {sock_buffer_size}");
if (sock_buffer_size as u64)
< 2 * (sender.config.encoding_block_size + sender.config.repair_block_size as u64)
< 2 * (sender.config.encoding_block_size + u64::from(sender.config.repair_block_size))
{
log::warn!("UDP socket send buffer may be too small to achieve optimal performances");
log::warn!("Please review the kernel parameters using sysctl");
Expand Down
18 changes: 9 additions & 9 deletions src/sock_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::os::fd::AsRawFd;
use std::{io, mem};
use std::{io, mem, ptr};

pub fn set_socket_send_buffer_size<S: AsRawFd>(socket: &S, size: i32) -> Result<(), io::Error> {
unsafe { setsockopt_buffer_size(socket.as_raw_fd(), size, libc::SO_SNDBUF) }
Expand All @@ -14,13 +14,13 @@ unsafe fn setsockopt_buffer_size(fd: i32, size: i32, option_name: i32) -> Result
fd,
libc::SOL_SOCKET,
option_name,
&size as *const libc::c_int as *const libc::c_void,
ptr::addr_of!(size).cast::<libc::c_void>(),
mem::size_of::<libc::c_int>() as libc::socklen_t,
);
if res != 0 {
Err(io::Error::new(io::ErrorKind::Other, "libc::setsockopt"))
} else {
if res == 0 {
Ok(())
} else {
Err(io::Error::new(io::ErrorKind::Other, "libc::setsockopt"))
}
}

Expand All @@ -39,12 +39,12 @@ unsafe fn getsockopt_buffer_size(fd: i32, option_name: i32) -> Result<i32, io::E
fd,
libc::SOL_SOCKET,
option_name,
&mut sz as *mut libc::c_int as *mut libc::c_void,
ptr::addr_of_mut!(sz).cast::<libc::c_void>(),
&mut len,
);
if res != 0 {
Err(io::Error::new(io::ErrorKind::Other, "libc::getsockopt"))
} else {
if res == 0 {
Ok(sz)
} else {
Err(io::Error::new(io::ErrorKind::Other, "libc::getsockopt"))
}
}
6 changes: 3 additions & 3 deletions src/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ impl<D> UdpMessages<D> {

for i in 0..vlen {
if let Some(msglen) = msglen {
iovecs[i].iov_base = buffers[i].as_mut_ptr() as *mut libc::c_void;
iovecs[i].iov_base = buffers[i].as_mut_ptr().cast::<libc::c_void>();
iovecs[i].iov_len = msglen;
}
if let Some(sockaddr) = &mut sockaddr {
msgvec[i].msg_hdr.msg_name =
sockaddr.as_mut() as *mut libc::sockaddr as *mut libc::c_void;
(sockaddr.as_mut() as *mut libc::sockaddr).cast::<libc::c_void>();
msgvec[i].msg_hdr.msg_namelen = mem::size_of::<libc::sockaddr_in>() as u32;
}
msgvec[i].msg_hdr.msg_iov = &mut iovecs[i];
Expand Down Expand Up @@ -132,7 +132,7 @@ impl UdpMessages<UdpSend> {

for (i, buf) in bufchunk.iter_mut().enumerate() {
self.msgvec[i].msg_len = buf.len() as u32;
self.iovecs[i].iov_base = buf.as_mut_ptr() as *mut libc::c_void;
self.iovecs[i].iov_base = buf.as_mut_ptr().cast::<libc::c_void>();
self.iovecs[i].iov_len = buf.len();
}

Expand Down

0 comments on commit 47c5a44

Please sign in to comment.