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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Deprecated compatibility entry points on the unprepared application.
//!
//! These methods rebuild a connection's route chains per connection, which
//! defeats preparation. They remain only so callers that predate
//! [`PreparedApp`](crate::app::PreparedApp) keep compiling, and each one
//! forwards to the shared connection path.
use std::{io, sync::Arc};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio_util::sync::CancellationToken;
use super::{
ConnectionProcessingContext,
Envelope,
Packet,
WireframeApp,
build_route_chains,
process_connection,
with_codec_frame_limit,
};
use crate::{
codec::FrameCodec,
frame::FrameMetadata,
message::{DecodeWith, EncodeWith},
serializer::Serializer,
};
impl<S, C, E, F> WireframeApp<S, C, E, F>
where
S: Serializer + FrameMetadata<Frame = Envelope> + Send + Sync + 'static,
C: Send + 'static,
E: Packet,
F: FrameCodec,
Envelope: DecodeWith<S> + EncodeWith<S>,
{
/// Drive one connection through rebuilt routes for compatibility callers.
///
/// Call `app.handle_unprepared_connection_result(stream).await` when a
/// per-connection factory still supplies a fresh application builder.
///
/// # Errors
///
/// Returns an [`io::Error`] if stream processing or handler execution fails.
pub(crate) async fn handle_unprepared_connection_result<W>(&self, stream: W) -> io::Result<()>
where
W: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
let routes = build_route_chains(&self.handlers, &self.middleware).await;
// This compatibility path has no server shutdown signal, so its
// connection token is never cancelled from outside.
let shutdown = CancellationToken::new();
process_connection(
stream,
ConnectionProcessingContext {
routes: &routes,
streaming_routes: &self.streaming_handlers,
serializer: self.serializer.as_ref(),
codec: &self.codec,
on_connect: self.on_connect.as_deref(),
on_disconnect: self.on_disconnect.as_deref(),
message_assembler: self.message_assembler.as_deref(),
fragmentation: self.fragmentation,
protocol_hooks: self.protocol_hooks(),
memory_budgets: self.memory_budgets,
recovery_hook: self.recovery_hook.as_deref(),
recovery_config: self.recovery_config.clone(),
read_timeout_ms: self.read_timeout_ms,
shutdown: &shutdown,
push_queues: with_codec_frame_limit(
self.push_queues.clone().unwrap_or_default(),
&self.codec,
),
session_registry: Arc::clone(&self.session_registry),
// This compatibility path is handed a stream rather than an
// accepted socket, so it has no peer address to report.
peer_addr: None,
},
)
.await
}
/// Handle a connection through a compatibility route preparation path.
///
/// # Errors
///
/// Returns an [`io::Error`] if stream processing or handler execution fails.
#[deprecated(
since = "0.4.0",
note = "prepare the app once, then call PreparedApp::handle_connection_result"
)]
pub async fn handle_connection_result<W>(&self, stream: W) -> io::Result<()>
where
W: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
self.handle_unprepared_connection_result(stream).await
}
/// Handle a connection through the compatibility preparation path.
#[deprecated(
since = "0.4.0",
note = "prepare the app once, then call PreparedApp::handle_connection"
)]
pub async fn handle_connection<W>(&self, stream: W)
where
W: AsyncRead + AsyncWrite + Send + Unpin + 'static,
{
if let Err(error) = self.handle_unprepared_connection_result(stream).await {
// Structured fields keep these failures filterable alongside the
// runtime's diagnostics; there is no correlation identifier on a
// connection this path has only just accepted.
tracing::warn!(
error = %error,
correlation_id = tracing::field::Empty,
"connection handling completed with error"
);
}
}
}