monoio_transports_netreq_fork/
lib.rs

1//! # monoio-transports
2//!
3//! `monoio-transports` is a high-performance, modular networking library built on top of the monoio
4//! asynchronous runtime. It provides a set of connectors and utilities for efficient network
5//! communications, optimized for use with io_uring.
6//!
7//! ## Key Features
8//!
9//! - Modular and stackable connector architecture
10//! - Support for various transport layers (TCP, Unix Domain Sockets)
11//! - TLS support for secure communications
12//! - HTTP/1.1 and HTTP/2 protocol support
13//! - Advanced connection pooling for optimal performance
14//! - Optimized for monoio's asynchronous runtime and io_uring
15//! - High-performance client implementations with built-in connection reuse
16//!
17//! ## Core Concepts
18//!
19//! ### Connector Trait
20//!
21//! The [`Connector`](crate::connectors::Connector) trait is the foundation of this crate's modular
22//! architecture. It defines a common interface for establishing network connections:
23//!
24//! ```rust
25//! pub trait Connector<K> {
26//!     type Connection;
27//!     type Error;
28//!     fn connect(&self, key: K) -> impl Future<Output = Result<Self::Connection, Self::Error>>;
29//! }
30//! ```
31//!
32//! This trait allows for the creation of various connector types that can be easily composed
33//! and stacked to create complex connection setups.
34//!
35//! ### TransportConnMetadata Trait
36//!
37//! The [`TransportConnMetadata`](crate::connectors::TransportConnMetadata) trait provides a way to
38//! retrieve additional information about a connection, such as ALPN (Application-Layer Protocol
39//! Negotiation) details:
40//!
41//! ```rust
42//! pub trait TransportConnMetadata {
43//!     type Metadata;
44//!     fn get_conn_metadata(&self) -> Self::Metadata;
45//! }
46//! ```
47//!
48//! ## Connector Types
49//!
50//! ### L4 Connectors
51//!
52//! - [`TcpConnector`](crate::connectors::TcpConnector): Establishes TCP connections
53//! - [`UnixConnector`](crate::connectors::UnixConnector): Establishes Unix Domain Socket
54//!   connections
55//! - [`UnifiedL4Connector`](crate::connectors::UnifiedL4Connector): A unified connector supporting
56//!   both TCP and Unix Domain Sockets
57//!
58//! ### TLS Connector
59//!
60//! [`TlsConnector`](crate::connectors::TlsConnector) adds TLS encryption to an underlying L4
61//! connector, supporting both native-tls and rustls backends.
62//!
63//! ### HTTP Connector
64//!
65//! [`HttpConnector`](crate::http::HttpConnector) is a universal connector supporting both HTTP/1.1
66//! and HTTP/2 protocols. It can be used with various underlying connectors (TCP, Unix, TLS) and
67//! provides built-in connection pooling for efficient resource usage and high performance.
68//!
69//! ### Connection Pooling
70//!
71//! The crate provides a generic, flexible connection pooling implementation that can be used
72//! with any type of connection:
73//!
74//! - [`ConnectionPool`](crate::pool::ConnectionPool): A generic pool that can manage and reuse any
75//!   type of connection.
76//! - [`PooledConnector`](crate::pool::PooledConnector):: A wrapper that adds pooling capabilities
77//!   to any connector.
78//!
79//! This generic pooling system is currently utilized in:
80//!
81//! - [`HttpConnector`](crate::http::HttpConnector): Leverages connection pooling for both HTTP/1.1
82//!   and HTTP/2.
83//! - Hyper connectors (when the `hyper` feature is enabled): Utilize the pooling system for
84//!   efficient connection reuse compatible with the Hyper ecosystem.
85//!
86//! The flexibility of this pooling implementation allows developers to easily add
87//! connection reuse capabilities to their custom connectors or any other connection types.
88//! This results in high-performance clients that efficiently manage connections,
89//! significantly improving throughput and reducing latency in high-load scenarios across
90//! various protocols and connection types.
91//!
92//! ## Stacking Connectors
93//!
94//! Connectors can be easily stacked to create powerful, flexible connection setups. For example:
95//!
96//! ```rust
97//! use monoio_transports::{
98//!     connectors::{TcpConnector, TlsConnector},
99//!     HttpConnector,
100//! };
101//!
102//! // Simple TCP conenctor
103//! let tcp_connector = TcpConnector::default();
104//! // TLS conencttor with custom ALPN protocols set
105//! let tls_connector = TlsConnector::new_with_tls_default(tcp_connector, Some(vec!["http/1.1"]));
106//! // Https conector with HTTP_2 and HTTP_11 support.
107//! let https_connector: HttpConnector<TlsConnector<TcpConnector>, _, _> = HttpConnector::default();
108//! ```
109//!
110//! This example creates a connector stack that uses TCP for the base connection, adds TLS
111//! encryption, and then provides HTTP protocol handling on top with built-in connection pooling.
112//!
113//! ## Feature Flags
114//!
115//! - `native-tls`: Enables the native-tls backend for TLS connections
116//! - `hyper`: Enables integration with the Hyper HTTP library, including Hyper-compatible
117//!   connectors with efficient connection pooling
118//!
119//! By leveraging monoio's efficient asynchronous runtime, io_uring, and advanced connection
120//! pooling, `monoio-transports` provides a powerful and flexible toolkit for building
121//! high-performance network applications and HTTP clients.
122#[cfg(not(feature = "default-crate"))]
123mod error;
124#[cfg(not(feature = "default-crate"))]
125pub use error::*;
126#[cfg(not(feature = "default-crate"))]
127pub mod connectors;
128#[cfg(not(feature = "default-crate"))]
129pub mod http;
130#[allow(dead_code)]
131#[cfg(not(feature = "default-crate"))]
132pub mod pool;
133
134
135#[cfg(feature = "default-crate")]
136pub use monoio_transports::*;