wireframe/app/inbound_handler/
compat.rs1use 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 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 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 peer_addr: None,
78 },
79 )
80 .await
81 }
82
83 #[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 #[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 tracing::warn!(
113 error = %error,
114 correlation_id = tracing::field::Empty,
115 "connection handling completed with error"
116 );
117 }
118 }
119}