Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
chrono = "0.4"
clap = { version = "4.4", features = ["derive", "wrap_help"] }
core_affinity = "0.8"
ctrlc2 = "3.5"
ctrlc2 = { version = "3.5", features = ["termination"] }
env_logger = "0.10"
log = { version = "0.4", features = ["std"] }
mio = { version = "0.8", features = ["log", "os-poll", "net"] }
Expand Down
3 changes: 1 addition & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::{
results::{IntervalResultBox, IntervalResultKind, TcpTestResults, TestResults, UdpTestResults},
},
stream::{tcp, udp, TestStream},
BoxResult,
};
use mio::net::TcpStream;
use std::{
Expand All @@ -40,8 +41,6 @@ use std::{
time::{Duration, SystemTime, UNIX_EPOCH},
};

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;

/// when false, the system is shutting down
static ALIVE: AtomicBool = AtomicBool::new(true);

Expand Down
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod args;
pub mod client;
pub(crate) mod protocol;
pub mod server;
pub(crate) mod stream;
pub(crate) mod utils;

pub(crate) type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
10 changes: 3 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
* along with rperf. If not, see <https://www.gnu.org/licenses/>.
*/

mod args;
mod client;
mod protocol;
mod server;
mod stream;
mod utils;
use rperf::{args, client, server};

fn main() {
use clap::Parser;
Expand All @@ -37,7 +32,7 @@ fn main() {

if args.server {
log::debug!("registering SIGINT handler...");
ctrlc2::set_handler(move || {
let exiting = ctrlc2::set_handler(move || {
if server::kill() {
log::warn!("shutdown requested; please allow a moment for any in-progress tests to stop");
} else {
Expand All @@ -50,6 +45,7 @@ fn main() {

log::debug!("beginning normal operation...");
let service = server::serve(&args);
exiting.join().expect("unable to join SIGINT handler thread");
if service.is_err() {
log::error!("unable to run server: {}", service.unwrap_err());
std::process::exit(4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exit-code is important to help determine whether an environmental error has occurred. I must ask that it not be suppressed -- the changes here would replace it with 1.

Expand Down
2 changes: 1 addition & 1 deletion src/protocol/communication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::time::Duration;
use mio::net::TcpStream;
use mio::{Events, Interest, Poll, Token};

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
use crate::BoxResult;

/// how long to wait for keepalive events
// the communications channels typically exchange data every second, so 2s is reasonable to avoid excess noise
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with rperf. If not, see <https://www.gnu.org/licenses/>.
*/

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
use crate::BoxResult;

/// prepares a message used to tell the server to begin operations
pub fn prepare_begin() -> serde_json::Value {
Expand Down
6 changes: 2 additions & 4 deletions src/protocol/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
* along with rperf. If not, see <https://www.gnu.org/licenses/>.
*/

use crate::BoxResult;
use serde::{Deserialize, Serialize};
use std::collections::{HashMap, HashSet};
use std::time::{SystemTime, UNIX_EPOCH};

use serde::{Deserialize, Serialize};

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;

/* This module contains structures used to represent and collect the results of tests.
* Since everything is basically just a data-container with representation methods,
* it isn't extensively documented.
Expand Down
12 changes: 9 additions & 3 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ use crate::protocol::communication::{receive, send, KEEPALIVE_DURATION};
use crate::protocol::messaging::{prepare_connect, prepare_connect_ready};
use crate::protocol::results::ServerDoneResult;
use crate::stream::{tcp, udp, TestStream};

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
use crate::BoxResult;

const POLL_TIMEOUT: Duration = Duration::from_millis(500);

Expand Down Expand Up @@ -335,7 +334,14 @@ pub fn serve(args: &Args) -> BoxResult<()> {
let mut events = Events::with_capacity(32);

while is_alive() {
poll.poll(&mut events, Some(POLL_TIMEOUT))?;
if let Err(err) = poll.poll(&mut events, Some(POLL_TIMEOUT)) {
if err.kind() == std::io::ErrorKind::Interrupted {
log::debug!("Poll interrupted: \"{err}\", ignored, continue polling");
Copy link
Member

@flan flan Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message isn't consistent with other logging statements in this project: they all start with a lower-case letter and employ "[state]; [infinitive-action]" grammar, rather than "[state], [declarative-decision]"

Perhaps "poll interrupted, \"{err}\" ignored; resuming poll"

continue;
}
log::error!("Poll error: {}", err);
break;
}
for event in events.iter() {
event.token();
loop {
Expand Down
2 changes: 1 addition & 1 deletion src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
pub mod tcp;
pub mod udp;

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
use crate::BoxResult;

pub const INTERVAL: std::time::Duration = std::time::Duration::from_secs(1);

Expand Down
3 changes: 1 addition & 2 deletions src/stream/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
use nix::sys::socket::{setsockopt, sockopt::RcvBuf, sockopt::SndBuf};

use crate::protocol::results::{get_unix_timestamp, IntervalResult, TcpReceiveResult, TcpSendResult};
use crate::BoxResult;

use super::{parse_port_spec, TestStream, INTERVAL};

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;

pub const TEST_HEADER_SIZE: usize = 16;

#[derive(Clone)]
Expand Down
3 changes: 1 addition & 2 deletions src/stream/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
use nix::sys::socket::{setsockopt, sockopt::RcvBuf, sockopt::SndBuf};

use crate::protocol::results::{get_unix_timestamp, IntervalResult, UdpReceiveResult, UdpSendResult};
use crate::BoxResult;

use super::{parse_port_spec, TestStream, INTERVAL};

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;

pub const TEST_HEADER_SIZE: u16 = 36;
const UDP_HEADER_SIZE: u16 = 8;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/cpu_affinity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with rperf. If not, see <https://www.gnu.org/licenses/>.
*/

type BoxResult<T> = Result<T, Box<dyn std::error::Error + Send + Sync + 'static>>;
use crate::BoxResult;

pub struct CpuAffinityManager {
enabled_cores: Vec<core_affinity::CoreId>,
Expand Down