1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! Server lifecycle and connection management.
//!
//! This module provides the building blocks for HTTP server lifecycle:
//!
//! - [`ShutdownSignal`] — Phase-aware shutdown coordination with drain timeouts
//! - [`ShutdownPhase`] — Shutdown state machine (Running → Draining → ForceClosing → Stopped)
//! - [`ConnectionManager`] — Active connection tracking with capacity limits
//! - [`ConnectionGuard`] — RAII guard for automatic connection deregistration
//!
//! These types build on the lower-level [`ShutdownController`](crate::signal::ShutdownController)
//! to provide server-specific lifecycle management with structured concurrency semantics.
//!
//! # Architecture
//!
//! ```text
//! Server Region (lifetime: until shutdown)
//! │
//! ├── Acceptor (stops on ShutdownSignal::begin_drain)
//! │
//! └── Connections (tracked by ConnectionManager)
//! ├── Connection[1] (holds ConnectionGuard)
//! │ ├── Request[1.1]
//! │ └── Request[1.2]
//! └── Connection[2]
//! ```
//!
//! # Example
//!
//! ```ignore
//! use asupersync::server::{ConnectionManager, ShutdownSignal};
//! use std::time::Duration;
//! use std::net::SocketAddr;
//!
//! let signal = ShutdownSignal::new();
//! let manager = ConnectionManager::new(Some(10_000), signal.clone());
//!
//! // Accept loop checks shutdown signal:
//! while !signal.is_shutting_down() {
//! // let (stream, addr) = listener.accept().await?;
//! # let addr: SocketAddr = "127.0.0.1:1234".parse().unwrap();
//! if let Some(guard) = manager.register(addr) {
//! // spawn connection handler with guard
//! }
//! }
//!
//! // Initiate graceful shutdown with 30s drain:
//! manager.begin_drain(Duration::from_secs(30));
//! manager.wait_all_closed().await;
//! signal.mark_stopped();
//! ```
pub use ;
pub use ;