#![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 crc32c;
mod driver;
mod error;
mod events;
mod gate;
mod handoff;
mod id;
mod info;
mod inherit;
mod limits;
mod link;
#[cfg(feature = "local")]
mod local;
#[cfg(all(windows, feature = "local"))]
mod local_windows;
mod opts;
#[cfg(all(windows, feature = "local"))]
mod pipe;
mod proxy;
#[cfg(feature = "proxy")]
mod proxy_parse;
mod rate;
mod server;
mod session;
mod sys;
mod tcp;
#[cfg(test)]
mod testing;
mod time;
mod tls;
mod trusted;
#[cfg(feature = "udp")]
mod udp;
#[cfg_attr(not(test), allow(dead_code))]
mod wheel;
#[cfg(fuzzing)]
#[doc(hidden)]
pub mod __fuzz {
pub fn manifest(data: &[u8]) {
crate::handoff::fuzz_manifest(data);
}
pub fn systemd_env(data: &[u8]) {
crate::inherit::fuzz_systemd_env(data);
}
}
#[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};
#[cfg(feature = "reactor")]
pub use driver::new_reactor_driver;
pub use driver::{
BorrowedSocket, Completion, Completions, Driver, DriverKind, DriverWaker, Operation,
OperationKind, Rejected, SendChunks, Token,
};
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, HandoffPeer, ListenerHandle};
#[cfg(all(windows, feature = "local"))]
pub use handoff::{SharedListeners, receive_shared, share_listeners};
#[cfg(all(unix, feature = "local"))]
pub use handoff::{recv_listeners, send_listeners};
pub use id::{ConnectionId, ListenerId, WorkerId};
pub use info::{
ConnectionInfo, Endpoint, GateTag, Lane, Origin, PeerCredentials, PipeName, Transport, UnixPath,
};
#[cfg(unix)]
pub use inherit::fastcgi_listener;
pub use inherit::{InheritError, InheritedListener, systemd, systemd_named};
pub use limits::{Limits, LimitsBuilder, MinRate, Pressure, SizeClass};
#[cfg(all(unix, feature = "local"))]
pub use local::{Descriptors, UnixConnection, UnixListener};
#[cfg(feature = "local")]
pub use local::{LocalConnection, LocalListener};
#[cfg(all(windows, feature = "local"))]
pub use local_windows::{UnixConnection, UnixListener};
pub use opts::{Keepalive, Linger, ListenOptions, LocalOptions, SocketOptions, TcpOptions};
#[cfg(all(windows, feature = "local"))]
pub use pipe::{PipeConnection, PipeListener, PipeOptions, PipeSecurity};
pub use proxy::{ProxyError, ProxyFacts, ProxyMode, ProxyVersions};
#[cfg(feature = "proxy")]
pub use proxy_parse::{
ProxyAddress, ProxyCommand, ProxyHeader, ProxyParser, ProxyProgress, ProxySsl, ProxyTransport,
Tlv, Tlvs, encode_v1, encode_v2,
};
#[cfg(feature = "udp")]
pub use server::UdpOnly;
pub use server::{
AdoptSpec, BlockingHandler, DoorState, DrainReport, ListenerSpec, NoGate, NoWork, Placement,
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, monotonic_micros};
pub use tls::{
NoTls, NoTlsSession, TlsAcceptor, TlsCloseKind, TlsError, TlsEvent, TlsFailure, TlsInfo,
TlsProgress, TlsSession,
};
pub use trusted::TrustedProxies;
#[cfg(feature = "udp")]
pub use udp::{
Datagram, DatagramBuffer, MulticastInterface, OutgoingDatagram, UdpBudget, UdpContext,
UdpOptions, UdpSession, UdpSessionFactory, UdpSocket, UdpStats,
};
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(feature = "local")]
pub fn listen_local(name: &str) -> Result<LocalListener, NetError> {
local::listen(name)
}
#[cfg(feature = "local")]
pub fn connect_local(name: &str) -> Result<LocalConnection, NetError> {
local::connect(name)
}
#[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");
}
}