diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-14 17:30:12 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-14 17:30:12 -0400 |
commit | 9c905d3c7c28ce27a78d2b2bafa27983c7446383 (patch) | |
tree | d638dc64a88e54f598f12267c810d3ec1f2337af | |
parent | dce20e1bbf4eb8c1268ff12b99b7bb4395972371 (diff) | |
download | teleterm-9c905d3c7c28ce27a78d2b2bafa27983c7446383.tar.gz teleterm-9c905d3c7c28ce27a78d2b2bafa27983c7446383.zip |
more simplification
-rw-r--r-- | src/server.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/server.rs b/src/server.rs index 6752849..0de39ba 100644 --- a/src/server.rs +++ b/src/server.rs @@ -236,12 +236,16 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> }) } + fn send_message(&mut self, message: crate::protocol::Message) { + self.to_send.push_back(message); + } + fn close(&mut self, res: Result<()>) { let msg = match res { Ok(()) => crate::protocol::Message::disconnected(), Err(e) => crate::protocol::Message::error(&format!("{}", e)), }; - self.to_send.push_back(msg); + self.send_message(msg); self.closed = true; } } @@ -333,8 +337,9 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> log::info!("{}: watch({}, {})", conn.id, username, id); conn.state.watch(&id); - conn.to_send - .push_back(crate::protocol::Message::terminal_output(data)); + conn.send_message(crate::protocol::Message::terminal_output( + data, + )); Ok(()) } else { @@ -346,8 +351,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> &mut self, conn: &mut Connection<S>, ) -> Result<()> { - conn.to_send - .push_back(crate::protocol::Message::heartbeat()); + conn.send_message(crate::protocol::Message::heartbeat()); Ok(()) } @@ -363,7 +367,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> for watch_conn in self.watchers_mut() { let watch_id = watch_conn.state.watch_id().unwrap(); if conn.id == watch_id { - watch_conn.to_send.push_back( + watch_conn.send_message( crate::protocol::Message::terminal_output(data), ); } @@ -380,8 +384,7 @@ impl<S: tokio::io::AsyncRead + tokio::io::AsyncWrite + Send + 'static> ) -> Result<()> { let sessions: Vec<_> = self.streamers().flat_map(Connection::session).collect(); - conn.to_send - .push_back(crate::protocol::Message::sessions(&sessions)); + conn.send_message(crate::protocol::Message::sessions(&sessions)); Ok(()) } |