From d71ac26b9397a23d018b60a7e42ac7be455a9b55 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 3 Mar 2019 05:08:58 -0800 Subject: [PATCH] add very bare bones skeleton for unix domain socket bits --- Cargo.toml | 3 +++ src/main.rs | 1 + src/server/client.rs | 1 + src/server/listener.rs | 33 +++++++++++++++++++++++++++++++++ src/server/mod.rs | 7 +++++++ 5 files changed, 45 insertions(+) create mode 100644 src/server/client.rs create mode 100644 src/server/listener.rs create mode 100644 src/server/mod.rs diff --git a/Cargo.toml b/Cargo.toml index c0d56dac0..f8f5438dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,9 @@ path = "term" [dependencies.termwiz] path = "termwiz" +[target."cfg(windows)".dependencies.uds_windows] +version = "0.1" + [target."cfg(windows)".dependencies.winapi] features = [ "winuser", diff --git a/src/main.rs b/src/main.rs index 7a55b0164..2d35dcafc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ mod guicommon; mod guiloop; mod mux; mod opengl; +mod server; use crate::guicommon::tabs::Tab; use crate::guiloop::GuiSelection; use crate::guiloop::GuiSystem; diff --git a/src/server/client.rs b/src/server/client.rs new file mode 100644 index 000000000..4e75131ff --- /dev/null +++ b/src/server/client.rs @@ -0,0 +1 @@ +pub struct Client {} diff --git a/src/server/listener.rs b/src/server/listener.rs new file mode 100644 index 000000000..b03578a8c --- /dev/null +++ b/src/server/listener.rs @@ -0,0 +1,33 @@ +use crate::server::{UnixListener, UnixStream}; +use failure::Error; +use std::io::{Read, Write}; + +pub trait SocketLike: Read + Write + Send {} + +pub trait Acceptor { + fn accept(&self) -> Result, Error>; +} + +impl SocketLike for UnixStream {} + +impl Acceptor for UnixListener { + fn accept(&self) -> Result, Error> { + let (stream, _addr) = UnixListener::accept(self)?; + let timeout = std::time::Duration::new(60, 0); + stream.set_read_timeout(Some(timeout))?; + stream.set_write_timeout(Some(timeout))?; + Ok(Box::new(stream)) + } +} + +pub struct Listener { + acceptor: Box, +} + +impl Listener { + pub fn new(acceptor: Box) -> Self { + Self { acceptor } + } +} + +pub struct ClientSession {} diff --git a/src/server/mod.rs b/src/server/mod.rs new file mode 100644 index 000000000..dbbd6a344 --- /dev/null +++ b/src/server/mod.rs @@ -0,0 +1,7 @@ +#[cfg(unix)] +use std::os::unix::net::{SocketAddr, UnixListener, UnixStream}; +#[cfg(windows)] +use uds_windows::{SocketAddr, UnixListener, UnixStream}; + +pub mod client; +pub mod listener;