From 33004abc12eae35b394df76dc7da5b5a6a1044c1 Mon Sep 17 00:00:00 2001 From: Aaron Weiss Date: Sun, 3 Jan 2016 08:32:45 -0500 Subject: [PATCH] Fixed a bug with the drop behavior for IrcServer. --- src/client/server/mod.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/client/server/mod.rs b/src/client/server/mod.rs index 2c76ee0..5b454ad 100644 --- a/src/client/server/mod.rs +++ b/src/client/server/mod.rs @@ -36,8 +36,8 @@ pub trait Server<'a, T: IrcRead, U: IrcWrite> { /// A thread-safe implementation of an IRC Server connection. pub struct IrcServer { - state: Arc>, tx: Sender, + state: Arc>, } /// Thread-safe internal state for an IRC server connection. @@ -83,7 +83,7 @@ impl IrcServer, BufWriter> { impl Clone for IrcServer { fn clone(&self) -> IrcServer { - IrcServer { state: self.state.clone(), tx: self.tx.clone() } + IrcServer { tx: self.tx.clone(), state: self.state.clone() } } } @@ -143,18 +143,15 @@ impl IrcServer { alt_nick_index: RwLock::new(0), }); let weak = Arc::downgrade(&state); - let write_handle = spawn(move || { - while let Some(strong) = weak.upgrade() { - match rx.recv() { - Ok(msg) => { IrcServer::write(&strong, msg); }, - Err(_) => () - } + let write_handle = spawn(move || while let Ok(msg) = rx.recv() { + if let Some(strong) = weak.upgrade() { + IrcServer::write(&strong, msg); } }); let state2 = state.clone(); let mut handle = state2.write_handle.lock().unwrap(); *handle = Some(write_handle); - IrcServer { state: state, tx: tx } + IrcServer { tx: tx, state: state } } /// Gets a reference to the IRC server's connection.