pub mod epoll_manager;
pub mod zero_copy_io;
pub mod batch_processor;
pub mod buffer_pool;
pub mod statistics;
pub mod sendfile; pub mod splice; pub mod tcp_socket; pub mod udp_socket; pub mod connection_pool; pub mod http2_server; pub mod http3_server; pub mod zero_copy; pub mod memory_mapper; pub mod zero_copy_network;
pub mod batch_io;
pub mod async_zero_copy;
pub mod network_buffer;
pub mod io_uring;
pub mod stage93_intelligent_prefetch;
pub mod stage93_network_topology;
use std::collections::{BTreeMap, HashMap};
use std::sync::{Arc, Mutex};
use std::time::Duration;
pub use zero_copy_network::{
ZeroCopySocket, ZeroCopyListener, ZeroCopyStream,
ZeroCopyConfig, NetworkZeroCopyStats
};
pub use batch_io::{
BatchIoEngine, BatchOperation, BatchConfig,
BatchStats, BatchPriority
};
pub use async_zero_copy::{
AsyncZeroCopy, ZeroCopyError, TransferRequest,
TransferStats, ZeroCopyFuture
};
pub use network_buffer::{
NetworkBuffer, BufferPool, BufferConfig,
BufferStats, BufferType
};
pub use io_uring::{
IoUringEngine, UringSubmission, UringCompletion,
UringConfig, UringStats
};
pub use stage93_intelligent_prefetch::{
Stage93IntelligentPrefetcher, PrefetchConfig, PrefetchStats,
AccessPattern, AIPrefetchPredictor
};
pub use stage93_network_topology::{
Stage93TopologyDiscoverer, TopologyConfig, NetworkTopology,
NetworkNode, NetworkPath, NodeType
};
#[derive(Debug, Clone)]
pub struct NetworkConfig {
pub max_connections: usize,
pub batch_size: usize,
pub batch_timeout: Duration,
pub max_buffer_size: usize,
pub enable_http2: bool,
pub enable_http3: bool,
pub pool_size: usize,
pub udp_buffer_size: usize,
}
impl Default for NetworkConfig {
fn default() -> Self {
Self {
max_connections: 10000,
batch_size: 100,
batch_timeout: Duration::from_millis(10),
max_buffer_size: 64 * 1024,
enable_http2: false,
enable_http3: false,
pool_size: 100,
udp_buffer_size: 32 * 1024,
}
}
}
#[derive(Debug, Clone)]
pub struct NetworkStats {
pub total_connections: usize,
pub active_connections: usize,
pub zero_copy_operations: usize,
pub total_bytes_sent: u64,
pub total_bytes_received: u64,
pub batch_operations: usize,
pub average_latency_us: u64,
pub memory_usage: usize,
}
#[derive(Debug, Clone, PartialEq)]
pub enum NetworkEvent {
NewConnection,
DataReceived,
ConnectionClosed,
Error(String),
}
#[derive(Debug, thiserror::Error)]
pub enum NetworkError {
#[error("I/O 错误: {0}")]
Io(#[from] std::io::Error),
#[error("超时错误")]
Timeout,
#[error("连接错误: {0}")]
Connection(String),
#[error("协议错误: {0}")]
Protocol(String),
#[error("资源不足")]
ResourceExhausted,
}
pub trait NetworkEventHandler: Send + Sync {
fn handle_event(&self, event: NetworkEvent) -> Result<(), NetworkError>;
}
pub struct NetworkMonitor {
stats: std::sync::Arc<std::sync::Mutex<NetworkStats>>,
}
impl NetworkMonitor {
pub fn new() -> Self {
Self {
stats: std::sync::Arc::new(std::sync::Mutex::new(NetworkStats {
total_connections: 0,
active_connections: 0,
zero_copy_operations: 0,
total_bytes_sent: 0,
total_bytes_received: 0,
batch_operations: 0,
average_latency_us: 0,
memory_usage: 0,
})),
}
}
pub fn update_stats(&self, updater: fn(&mut NetworkStats)) {
if let Ok(mut stats) = self.stats.lock() {
updater(&mut stats);
}
}
pub fn get_stats_snapshot(&self) -> NetworkStats {
self.stats.lock().unwrap().clone()
}
}
impl Default for NetworkMonitor {
fn default() -> Self {
Self::new()
}
}