From 1d2b4291d398573a92f600c898108b90feb33926 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 16 Jun 2019 07:40:05 -0700 Subject: [PATCH] prep for dealing with unilaterally sent pdus --- src/main.rs | 6 +++--- src/server/client.rs | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 618f13406..bd2d3e62e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -146,10 +146,10 @@ fn run_terminal_gui(config: Arc, opts: &StartCommand) -> Result< }; let domain: Arc = if opts.mux_client_as_default_domain { - let client = Client::new_unix_domain(&config)?; + let client = Client::new_unix_domain(&config, None)?; Arc::new(ClientDomain::new(client)) } else if opts.mux_tls_client_as_default_domain { - let client = Client::new_tls(&config)?; + let client = Client::new_tls(&config, None)?; Arc::new(ClientDomain::new(client)) } else { Arc::new(LocalDomain::new(&config)?) @@ -210,7 +210,7 @@ fn main() -> Result<(), Error> { run_terminal_gui(config, &start) } SubCommand::Cli(cli) => { - let client = Client::new_unix_domain(&config)?; + let client = Client::new_unix_domain(&config, None)?; match cli.sub { CliSubCommand::List => { let cols = vec![ diff --git a/src/server/client.rs b/src/server/client.rs index e73e31f29..c127e3246 100644 --- a/src/server/client.rs +++ b/src/server/client.rs @@ -57,8 +57,12 @@ macro_rules! rpc { }; } -fn client_thread(mut stream: Box, rx: Receiver) -> Fallible<()> { - let mut next_serial = 0u64; +fn client_thread( + mut stream: Box, + rx: Receiver, + _unilaterals: Option>, +) -> Fallible<()> { + let mut next_serial = 1u64; let mut promises = HashMap::new(); loop { let msg = if promises.is_empty() { @@ -104,11 +108,11 @@ fn client_thread(mut stream: Box, rx: Receiver) } impl Client { - pub fn new(stream: Box) -> Self { + pub fn new(stream: Box, unilaterals: Option>) -> Self { let (sender, receiver) = channel(); thread::spawn(move || { - if let Err(e) = client_thread(stream, receiver) { + if let Err(e) = client_thread(stream, receiver, unilaterals) { log::error!("client thread ended: {}", e); } }); @@ -116,7 +120,10 @@ impl Client { Self { sender } } - pub fn new_unix_domain(config: &Arc) -> Fallible { + pub fn new_unix_domain( + config: &Arc, + unilaterals: Option>, + ) -> Fallible { let sock_path = Path::new( config .mux_server_unix_domain_socket_path @@ -125,10 +132,10 @@ impl Client { ); info!("connect to {}", sock_path.display()); let stream = Box::new(UnixStream::connect(sock_path)?); - Ok(Self::new(stream)) + Ok(Self::new(stream, unilaterals)) } - pub fn new_tls(config: &Arc) -> Fallible { + pub fn new_tls(config: &Arc, unilaterals: Option>) -> Fallible { let remote_address = config .mux_server_remote_address .as_ref() @@ -171,7 +178,7 @@ impl Client { e ) })?); - Ok(Self::new(stream)) + Ok(Self::new(stream, unilaterals)) } pub fn send_pdu(&self, pdu: Pdu) -> Future {