From 098629536a9ac61afb42fd2f33121c0d37384705 Mon Sep 17 00:00:00 2001 From: Jovi Hsu Date: Wed, 17 Nov 2021 09:53:45 +0800 Subject: [PATCH] change how vnc generate c2s messages --- frontend/src/protocal/vnc.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/src/protocal/vnc.rs b/frontend/src/protocal/vnc.rs index 0783b38..d9a66bd 100644 --- a/frontend/src/protocal/vnc.rs +++ b/frontend/src/protocal/vnc.rs @@ -52,6 +52,7 @@ pub struct VncHandler { msg_handling: ServerMessage, num_rect_left: u16, padding_rect: Option, + outbuf: Vec, outs: Vec, } @@ -71,6 +72,7 @@ impl ProtocalImpl for VncHandler { msg_handling: ServerMessage::None, num_rect_left: 0, padding_rect: None, + outbuf: Vec::with_capacity(128), outs: Vec::with_capacity(10), } } @@ -95,6 +97,10 @@ impl ProtocalImpl for VncHandler { for o in self.outs.drain(..) { out.push(o); } + if !self.outbuf.is_empty() { + out.push(ProtocalHandlerOutput::WsBuf(self.outbuf.clone())); + self.outbuf.clear(); + } out } @@ -120,8 +126,7 @@ impl ProtocalImpl for VncHandler { // ConsoleService::log(&format!("challenge {:x?}", self.challenge)); let output = des::encrypt(&self.challenge, &key); - self.outs - .push(ProtocalHandlerOutput::WsBuf(output.to_vec())); + self.outbuf.extend_from_slice(&output); self.state = VncState::Authing; self.require = 4; // the auth result message length } @@ -202,8 +207,7 @@ impl VncHandler { // send client_init message let shared_flag = 0; - self.outs - .push(ProtocalHandlerOutput::WsBuf(vec![shared_flag])); + self.outbuf.push(shared_flag); } // No. of bytes Type [Value] Description @@ -223,7 +227,7 @@ impl VncHandler { sw.write_u16(0); sw.write_u16(self.width); sw.write_u16(self.height); - self.outs.push(ProtocalHandlerOutput::WsBuf(out)); + self.outbuf.extend_from_slice(&out); } fn handle_input(&mut self) { @@ -251,7 +255,7 @@ impl VncHandler { Ok(v) => { self.state = VncState::Handshake; self.require = 4; // the length of the security type message - self.outs.push(ProtocalHandlerOutput::WsBuf(v.to_vec())); + self.outbuf.extend_from_slice(v); } Err(e) => self.disconnect_with_err(e), }