From bddc352e1ffcaa0b8750e6bd090938f0860cbd28 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 13 Aug 2020 17:45:39 +0100 Subject: [PATCH] wip connect? --- src/bin/otter.rs | 19 ++++++++++++++++--- src/client.rs | 14 -------------- src/cmdlistener.rs | 2 +- src/mgmtchannel.rs | 2 +- src/spec.rs | 4 ++-- 5 files changed, 20 insertions(+), 21 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index 21a75885..2c4128ab 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -9,6 +9,8 @@ use std::rc::Rc; use std::cell::RefCell; use std::cell::Cell; +type E = anyhow::Error; + use argparse::action::ParseResult::Parsed; #[derive(Clone)] @@ -58,7 +60,7 @@ struct MainOpts { struct Subcommand ( &'static str, // command &'static str, // desc - fn(&Subcommand, MainOpts, Vec), + fn(&Subcommand, MainOpts, Vec) -> Result<(),E>, ); inventory::collect!(Subcommand); @@ -173,7 +175,15 @@ fn main() { env::args().next().unwrap(), &ma.subcommand)); - call(sc, ma.opts, subargs); + call(sc, ma.opts, subargs).expect("execution error"); +} + +type Conn = MgmtChannel; + +fn connect(ma: &MainOpts) -> Result<(),E> { + let unix = UnixStream::connect(SOCKET_PATH).context("connect to server")?; + + todo!() } inventory::submit!{Subcommand( @@ -196,6 +206,9 @@ inventory::submit!{Subcommand( Ok(()) }, None); - eprintln!("CREATE-TABLE {:?} {:?}", &mainopts, &args); + let chan = connect(&mainopts)?; + + eprintln!("CREATE-TABLE {:?} {:?} {:?}", &mainopts, &args, &chan); + Ok(()) } )} diff --git a/src/client.rs b/src/client.rs index a1124a52..e69de29b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,14 +0,0 @@ - -use crate::imports::*; - -pub struct MgmtConnection { - read : io::Lines>, - write : BufWriter, -} - -impl MgmtConnection { - fn connect() { - todo!(); -// let mut both = UnixStream:;connect(SOCKET_PATH)?; - } -} diff --git a/src/cmdlistener.rs b/src/cmdlistener.rs index e846faea..93dd7179 100644 --- a/src/cmdlistener.rs +++ b/src/cmdlistener.rs @@ -17,7 +17,7 @@ use pwd::Passwd; //use serde_json::ser::Serializer; //use serde_json::de::{IoRead,StreamDeserializer}; -const SOCKET_PATH : &str = "command.socket"; // xxx +pub const SOCKET_PATH : &str = "command.socket"; // xxx pub struct CommandListener { listener : UnixListener, diff --git a/src/mgmtchannel.rs b/src/mgmtchannel.rs index b3f1b488..0ca3216d 100644 --- a/src/mgmtchannel.rs +++ b/src/mgmtchannel.rs @@ -41,7 +41,7 @@ impl MgmtChannel { } } -trait IoTryClone : Sized { +pub trait IoTryClone : Sized { fn try_clone(&self) -> io::Result; } diff --git a/src/spec.rs b/src/spec.rs index d11b4dc3..35310aab 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -33,7 +33,7 @@ pub struct PiecesSpec { #[typetag::serde(tag="access")] pub trait PlayerAccessSpec : Debug { - fn deliver_token_client(&self, conn: &mut MgmtConnection, nick: &str) + fn deliver_token_client(&self, conn: &mut ()/*xxx*/, nick: &str) -> Result<(),anyhow::Error>; } @@ -42,7 +42,7 @@ struct UrlOnStdout; #[typetag::serde] impl PlayerAccessSpec for UrlOnStdout { - fn deliver_token_client(&self, conn: &mut MgmtConnection, nick: &str) + fn deliver_token_client(&self, conn: &mut (), nick: &str) -> Result<(),anyhow::Error> { todo!() } -- 2.30.2