#![doc(html_root_url = "https://docs.rs/net-io")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(unsafe_code)]
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(missing_docs)]
#![cfg_attr(
not(test),
deny(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::todo,
clippy::unimplemented,
clippy::dbg_macro,
clippy::print_stdout,
clippy::print_stderr
)
)]
mod accept;
mod addr;
mod buf;
mod completer;
mod control;
mod driver;
mod error;
mod events;
mod gate;
mod handoff;
mod id;
mod info;
mod inherit;
mod limits;
mod link;
mod opts;
mod proxy;
mod rate;
mod server;
mod session;
mod sys;
mod tcp;
#[cfg(test)]
mod testing;
mod time;
mod tls;
mod trusted;
#[cfg(net_io_shim)]
#[doc(hidden)]
pub mod __shim {
pub use crate::sys::shim::{Fault, Op, clear, counted, program, start_counting, stop_counting};
}
use std::net::ToSocketAddrs;
pub use addr::{AddrError, Cidr, PrefixKey, PrefixPolicy, normalize, normalize_socket};
pub use buf::{Buffer, BufferPool, PoolStats};
pub use completer::{Completer, PostError};
pub use control::{ControlLine, ControlState, NoControl, SimpleControl};
pub use driver::DriverKind;
pub use error::{
CloseReason, ConfigReason, Direction, ErrorClass, KillReason, LimitKind, NetError,
OsErrorClass, RefusalCause, TimeoutKind,
};
pub use events::{CoalescedKind, Event, EventSink, NoopSink};
pub use gate::{AdmitStage, Admitted, AllowAll, Denial, Gate, KillHandle, Refusal, WriteCheck};
pub use handoff::HandoffError;
pub use id::{ConnectionId, ListenerId, WorkerId};
pub use info::{
ConnectionInfo, Endpoint, GateTag, Lane, Origin, PeerCredentials, PipeName, Transport, UnixPath,
};
pub use inherit::InheritError;
pub use limits::{Limits, LimitsBuilder, MinRate, Pressure, SizeClass};
pub use opts::{Keepalive, Linger, ListenOptions, SocketOptions, TcpOptions};
pub use proxy::{ProxyError, ProxyFacts, ProxyMode, ProxyVersions};
pub use server::{
BlockingHandler, DoorState, DrainReport, ListenerSpec, NoGate, NoWork, Server, ServerBuilder,
ServerHandle, Sessions, Stats, Workload,
};
pub use session::{
Input, Output, OutputFull, Phase, Session, SessionContext, SessionFactory, Step, SwapError,
};
pub use tcp::{ConnectOptions, ListenerInfo, TcpConnection, TcpListener};
pub use time::{Clock, ManualClock, MonotonicClock};
pub use tls::{
NoTls, NoTlsSession, TlsAcceptor, TlsCloseKind, TlsError, TlsEvent, TlsFailure, TlsInfo,
TlsProgress, TlsSession,
};
pub use trusted::TrustedProxies;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub fn listen<A: ToSocketAddrs>(addr: A) -> Result<TcpListener, NetError> {
TcpListener::bind(addr)
}
pub fn connect<A: ToSocketAddrs>(addr: A) -> Result<TcpConnection, NetError> {
TcpConnection::connect(addr)
}
pub fn serve<A, F>(addr: A, handler: F) -> Result<Server, NetError>
where
A: ToSocketAddrs,
F: Fn(&mut TcpConnection) -> Result<(), NetError> + Send + Sync + 'static,
{
let server = ServerBuilder::new()
.listener(ListenerSpec::tcp(addr))
.driver(DriverKind::Blocking)
.handler(handler)
.gate(AllowAll)
.build()?;
server.open_door()?;
Ok(server)
}
pub fn serve_sessions<A, F>(addr: A, factory: F) -> Result<Server, NetError>
where
A: ToSocketAddrs,
F: SessionFactory,
{
let server = ServerBuilder::new()
.listener(ListenerSpec::tcp(addr))
.sessions(factory)
.gate(AllowAll)
.build()?;
server.open_door()?;
Ok(server)
}
#[cfg(test)]
mod tests {
use super::VERSION;
#[test]
fn test_version_matches_manifest() {
assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
assert_eq!(VERSION.split('.').count(), 3, "expected MAJOR.MINOR.PATCH");
}
}