make client generic over Read+Write rather than UnixStream
This commit is contained in:
1 parent
f86b65270b
commit
16bcf7cf54
2 files changed
+9
-6
No files matched your search
+2
-2
@@ -144,7 +144,7 @@ fn run_terminal_gui(config: Arc<config::Config>, opts: &StartCommand) -> Result<
|
||||
};
|
||||
|
||||
let domain: Arc<dyn Domain> = if opts.mux_client_as_default_domain {
|
||||
let client = Client::new(&config)?;
|
||||
let client = Client::new_unix_domain(&config)?;
|
||||
Arc::new(ClientDomain::new(client))
|
||||
} else {
|
||||
Arc::new(LocalDomain::new(&config)?)
|
||||
@@ -205,7 +205,7 @@ fn main() -> Result<(), Error> {
|
||||
run_terminal_gui(config, &start)
|
||||
}
|
||||
SubCommand::Cli(cli) => {
|
||||
let mut client = Client::new(&config)?;
|
||||
let mut client = Client::new_unix_domain(&config)?;
|
||||
match cli.sub {
|
||||
CliSubCommand::List => {
|
||||
let cols = vec![
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
use crate::config::Config;
|
||||
use crate::server::codec::*;
|
||||
use crate::server::UnixStream;
|
||||
use failure::{bail, ensure, err_msg, Error};
|
||||
use failure::{bail, ensure, err_msg, Error, Fallible};
|
||||
use log::info;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub trait ReadAndWrite: std::io::Read + std::io::Write {}
|
||||
impl ReadAndWrite for UnixStream {}
|
||||
|
||||
pub struct Client {
|
||||
stream: UnixStream,
|
||||
stream: Box<dyn ReadAndWrite>,
|
||||
serial: u64,
|
||||
}
|
||||
|
||||
@@ -38,7 +41,7 @@ macro_rules! rpc {
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub fn new(config: &Arc<Config>) -> Result<Self, Error> {
|
||||
pub fn new_unix_domain(config: &Arc<Config>) -> Fallible<Self> {
|
||||
let sock_path = Path::new(
|
||||
config
|
||||
.mux_server_unix_domain_socket_path
|
||||
@@ -46,7 +49,7 @@ impl Client {
|
||||
.ok_or_else(|| err_msg("no mux_server_unix_domain_socket_path"))?,
|
||||
);
|
||||
info!("connect to {}", sock_path.display());
|
||||
let stream = UnixStream::connect(sock_path)?;
|
||||
let stream = Box::new(UnixStream::connect(sock_path)?);
|
||||
Ok(Self { stream, serial: 0 })
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user