From 648f73c995da4fe080ebe8e50c97c817fb2b6d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 17 Sep 2024 13:51:32 +0400 Subject: [PATCH] refactor(server): lower function requirements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prepare for the next patch, and take "impl FramedWrite" rather than a Framed for the various dispatch methods. Signed-off-by: Marc-André Lureau --- crates/ironrdp-server/src/server.rs | 48 ++++++++++------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/crates/ironrdp-server/src/server.rs b/crates/ironrdp-server/src/server.rs index 752b63eb..5f874ce8 100644 --- a/crates/ironrdp-server/src/server.rs +++ b/crates/ironrdp-server/src/server.rs @@ -337,17 +337,14 @@ impl RdpServer { self.static_channels.get_channel_id_by_type::() } - async fn dispatch_pdu( + async fn dispatch_pdu( &mut self, action: Action, bytes: bytes::BytesMut, - writer: &mut Framed, + writer: &mut impl FramedWrite, io_channel_id: u16, user_channel_id: u16, - ) -> Result - where - W: FramedWrite, - { + ) -> Result { match action { Action::FastPath => { let input = decode(&bytes)?; @@ -369,18 +366,14 @@ impl RdpServer { Ok(RunState::Continue) } - async fn dispatch_display_update( - &mut self, + async fn dispatch_display_update( update: DisplayUpdate, - writer: &mut Framed, + writer: &mut impl FramedWrite, user_channel_id: u16, io_channel_id: u16, buffer: &mut Vec, mut encoder: UpdateEncoder, - ) -> Result<(RunState, UpdateEncoder)> - where - W: FramedWrite, - { + ) -> Result<(RunState, UpdateEncoder)> { let mut fragmenter = match update { DisplayUpdate::Bitmap(bitmap) => { let (enc, res) = task::spawn_blocking(move || { @@ -431,15 +424,12 @@ impl RdpServer { Ok((RunState::Continue, encoder)) } - async fn dispatch_server_events( + async fn dispatch_server_events( &mut self, events: &mut Vec, - writer: &mut Framed, + writer: &mut impl FramedWrite, user_channel_id: u16, - ) -> Result - where - W: FramedWrite, - { + ) -> Result { // Avoid wave message queuing up and causing extra delays. // This is a naive solution, better solutions should compute the actual delay, add IO priority, encode audio, use UDP etc. // 4 frames should roughly corresponds to hundreds of ms in regular setups. @@ -534,7 +524,7 @@ impl RdpServer { }, Some(update) = display_updates.next_update() => { - (state, encoder) = self.dispatch_display_update(update, writer, user_channel_id, io_channel_id, &mut buffer, encoder).await?; + (state, encoder) = Self::dispatch_display_update(update, writer, user_channel_id, io_channel_id, &mut buffer, encoder).await?; } nevents = self.ev_receiver.recv_many(&mut events, 100) => { @@ -652,16 +642,13 @@ impl RdpServer { Ok(state) } - async fn handle_input_backlog( + async fn handle_input_backlog( &mut self, - writer: &mut Framed, + writer: &mut impl FramedWrite, io_channel_id: u16, user_channel_id: u16, frames: Vec>, - ) -> Result<()> - where - W: FramedWrite, - { + ) -> Result<()> { for frame in frames { match Action::from_fp_output_header(frame[0]) { Ok(Action::FastPath) => { @@ -743,16 +730,13 @@ impl RdpServer { Ok(false) } - async fn handle_x224( + async fn handle_x224( &mut self, - writer: &mut Framed, + writer: &mut impl FramedWrite, io_channel_id: u16, user_channel_id: u16, frame: &[u8], - ) -> Result - where - W: FramedWrite, - { + ) -> Result { let message = decode::>>(frame)?; match message.0 { mcs::McsMessage::SendDataRequest(data) => {