Skip to main content

wireframe/app/inbound_handler/
compat.rs

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