mirror of
https://github.com/wez/wezterm.git
synced 2024-11-22 04:56:12 +03:00
move uds stuff into new wezterm-uds crate
This centralizes the conditional imports and makes a home for the IoSafe trait annotation for smol/async-io compat.
This commit is contained in:
parent
a597803c13
commit
0fcd4a847c
15
Cargo.lock
generated
15
Cargo.lock
generated
@ -6128,12 +6128,12 @@ dependencies = [
|
|||||||
"termwiz",
|
"termwiz",
|
||||||
"textwrap",
|
"textwrap",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"uds_windows",
|
|
||||||
"umask",
|
"umask",
|
||||||
"url",
|
"url",
|
||||||
"wezterm-dynamic",
|
"wezterm-dynamic",
|
||||||
"wezterm-ssh",
|
"wezterm-ssh",
|
||||||
"wezterm-term",
|
"wezterm-term",
|
||||||
|
"wezterm-uds",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -6281,7 +6281,6 @@ dependencies = [
|
|||||||
"textwrap",
|
"textwrap",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"tiny-skia",
|
"tiny-skia",
|
||||||
"uds_windows",
|
|
||||||
"umask",
|
"umask",
|
||||||
"unicode-normalization",
|
"unicode-normalization",
|
||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
@ -6373,10 +6372,10 @@ dependencies = [
|
|||||||
"rcgen",
|
"rcgen",
|
||||||
"smol",
|
"smol",
|
||||||
"termwiz",
|
"termwiz",
|
||||||
"uds_windows",
|
|
||||||
"url",
|
"url",
|
||||||
"wezterm-client",
|
"wezterm-client",
|
||||||
"wezterm-term",
|
"wezterm-term",
|
||||||
|
"wezterm-uds",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -6418,7 +6417,7 @@ dependencies = [
|
|||||||
"ssh2",
|
"ssh2",
|
||||||
"termwiz",
|
"termwiz",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"uds_windows",
|
"wezterm-uds",
|
||||||
"whoami",
|
"whoami",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -6469,6 +6468,14 @@ dependencies = [
|
|||||||
"zvariant",
|
"zvariant",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wezterm-uds"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"async-io",
|
||||||
|
"uds_windows",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "wezterm-version"
|
name = "wezterm-version"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
@ -11,7 +11,8 @@ members = [
|
|||||||
"wezterm-gui",
|
"wezterm-gui",
|
||||||
"wezterm-mux-server",
|
"wezterm-mux-server",
|
||||||
"wezterm-open-url",
|
"wezterm-open-url",
|
||||||
"wezterm-ssh"
|
"wezterm-ssh",
|
||||||
|
"wezterm-uds",
|
||||||
]
|
]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
exclude = [
|
exclude = [
|
||||||
|
@ -37,9 +37,9 @@ url = "2"
|
|||||||
wezterm-dynamic = { path = "../wezterm-dynamic" }
|
wezterm-dynamic = { path = "../wezterm-dynamic" }
|
||||||
wezterm-ssh = { path = "../wezterm-ssh" }
|
wezterm-ssh = { path = "../wezterm-ssh" }
|
||||||
wezterm-term = { path = "../term", features=["use_serde"] }
|
wezterm-term = { path = "../term", features=["use_serde"] }
|
||||||
|
wezterm-uds = { path = "../wezterm-uds" }
|
||||||
|
|
||||||
[target."cfg(windows)".dependencies]
|
[target."cfg(windows)".dependencies]
|
||||||
uds_windows = "1.1"
|
|
||||||
winapi = { version = "0.3", features = [
|
winapi = { version = "0.3", features = [
|
||||||
"winuser",
|
"winuser",
|
||||||
]}
|
]}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use crate::domain::{ClientDomain, ClientDomainConfig};
|
use crate::domain::{ClientDomain, ClientDomainConfig};
|
||||||
use crate::pane::ClientPane;
|
use crate::pane::ClientPane;
|
||||||
use crate::UnixStream;
|
|
||||||
use anyhow::{anyhow, bail, Context};
|
use anyhow::{anyhow, bail, Context};
|
||||||
use async_ossl::AsyncSslStream;
|
use async_ossl::AsyncSslStream;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@ -34,6 +33,7 @@ use std::path::{Path, PathBuf};
|
|||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
use wezterm_uds::UnixStream;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
#[error("Timeout")]
|
#[error("Timeout")]
|
||||||
@ -535,46 +535,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This wrapper makes UnixStream IoSafe on all platforms.
|
|
||||||
/// This isn't strictly needed on unix, because async-io
|
|
||||||
/// includes an impl for the std UnixStream, but on Windows
|
|
||||||
/// the uds_windows crate doesn't have an impl.
|
|
||||||
/// Here we define it for all platforms in the interest of
|
|
||||||
/// minimizing platform differences.
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct IoSafeUnixStream(UnixStream);
|
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
impl AsFd for IoSafeUnixStream {
|
|
||||||
fn as_fd(&self) -> BorrowedFd {
|
|
||||||
self.0.as_fd()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
impl AsSocket for IoSafeUnixStream {
|
|
||||||
fn as_socket(&self) -> BorrowedSocket {
|
|
||||||
self.0.as_socket()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Read for IoSafeUnixStream {
|
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
|
||||||
self.0.read(buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Write for IoSafeUnixStream {
|
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
|
|
||||||
self.0.write(buf)
|
|
||||||
}
|
|
||||||
fn flush(&mut self) -> Result<(), std::io::Error> {
|
|
||||||
self.0.flush()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl async_io::IoSafe for IoSafeUnixStream {}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Reconnectable {
|
struct Reconnectable {
|
||||||
config: ClientDomainConfig,
|
config: ClientDomainConfig,
|
||||||
@ -842,7 +802,7 @@ impl Reconnectable {
|
|||||||
ui.output_str("Connected!\n");
|
ui.output_str("Connected!\n");
|
||||||
stream.set_read_timeout(Some(unix_dom.read_timeout))?;
|
stream.set_read_timeout(Some(unix_dom.read_timeout))?;
|
||||||
stream.set_write_timeout(Some(unix_dom.write_timeout))?;
|
stream.set_write_timeout(Some(unix_dom.write_timeout))?;
|
||||||
let stream: Box<dyn AsyncReadAndWrite> = Box::new(Async::new(IoSafeUnixStream(stream))?);
|
let stream: Box<dyn AsyncReadAndWrite> = Box::new(Async::new(stream)?);
|
||||||
self.stream.replace(stream);
|
self.stream.replace(stream);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::UnixStream;
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
use wezterm_uds::UnixStream;
|
||||||
|
|
||||||
/// There's a lot more code in this windows module than I thought I would need
|
/// There's a lot more code in this windows module than I thought I would need
|
||||||
/// to write. Ostensibly, we could get away with making a symlink by taking
|
/// to write. Ostensibly, we could get away with making a symlink by taking
|
||||||
|
@ -1,8 +1,3 @@
|
|||||||
#[cfg(unix)]
|
|
||||||
use std::os::unix::net::UnixStream;
|
|
||||||
#[cfg(windows)]
|
|
||||||
use uds_windows::UnixStream;
|
|
||||||
|
|
||||||
pub mod client;
|
pub mod client;
|
||||||
pub mod discovery;
|
pub mod discovery;
|
||||||
pub mod domain;
|
pub mod domain;
|
||||||
|
@ -111,7 +111,6 @@ window-funcs = { path = "../lua-api-crates/window-funcs" }
|
|||||||
|
|
||||||
[target."cfg(windows)".dependencies]
|
[target."cfg(windows)".dependencies]
|
||||||
shared_library = "0.1"
|
shared_library = "0.1"
|
||||||
uds_windows = "1.1"
|
|
||||||
winapi = { version = "0.3", features = [
|
winapi = { version = "0.3", features = [
|
||||||
"winuser",
|
"winuser",
|
||||||
"consoleapi",
|
"consoleapi",
|
||||||
|
@ -26,8 +26,8 @@ smol = "2.0"
|
|||||||
url = "2"
|
url = "2"
|
||||||
wezterm-client = { path = "../wezterm-client" }
|
wezterm-client = { path = "../wezterm-client" }
|
||||||
wezterm-term = { path = "../term", features=["use_serde"] }
|
wezterm-term = { path = "../term", features=["use_serde"] }
|
||||||
|
wezterm-uds = { path = "../wezterm-uds" }
|
||||||
termwiz = { path = "../termwiz", features=["use_serde"] }
|
termwiz = { path = "../termwiz", features=["use_serde"] }
|
||||||
|
|
||||||
[target."cfg(windows)".dependencies]
|
[target."cfg(windows)".dependencies]
|
||||||
uds_windows = "1.1"
|
|
||||||
winapi = { version = "0.3", features = [ "winuser" ]}
|
winapi = { version = "0.3", features = [ "winuser" ]}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
use crate::sessionhandler::{PduSender, SessionHandler};
|
use crate::sessionhandler::{PduSender, SessionHandler};
|
||||||
use crate::UnixStream;
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use async_ossl::AsyncSslStream;
|
use async_ossl::AsyncSslStream;
|
||||||
use codec::{DecodedPdu, Pdu};
|
use codec::{DecodedPdu, Pdu};
|
||||||
@ -7,6 +6,7 @@ use futures::FutureExt;
|
|||||||
use mux::{Mux, MuxNotification};
|
use mux::{Mux, MuxNotification};
|
||||||
use smol::prelude::*;
|
use smol::prelude::*;
|
||||||
use smol::Async;
|
use smol::Async;
|
||||||
|
use wezterm_uds::UnixStream;
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub trait AsRawDesc: std::os::unix::io::AsRawFd + std::os::fd::AsFd {}
|
pub trait AsRawDesc: std::os::unix::io::AsRawFd + std::os::fd::AsFd {}
|
||||||
|
@ -5,11 +5,6 @@ use mux::Mux;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use wezterm_client::domain::{ClientDomain, ClientDomainConfig};
|
use wezterm_client::domain::{ClientDomain, ClientDomainConfig};
|
||||||
|
|
||||||
#[cfg(unix)]
|
|
||||||
use std::os::unix::net::{UnixListener, UnixStream};
|
|
||||||
#[cfg(windows)]
|
|
||||||
use uds_windows::{UnixListener, UnixStream};
|
|
||||||
|
|
||||||
pub mod dispatch;
|
pub mod dispatch;
|
||||||
pub mod local;
|
pub mod local;
|
||||||
pub mod pki;
|
pub mod pki;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::UnixListener;
|
|
||||||
use anyhow::{anyhow, Context as _};
|
use anyhow::{anyhow, Context as _};
|
||||||
use config::{create_user_owned_dirs, UnixDomain};
|
use config::{create_user_owned_dirs, UnixDomain};
|
||||||
use promise::spawn::spawn_into_main_thread;
|
use promise::spawn::spawn_into_main_thread;
|
||||||
|
use wezterm_uds::UnixListener;
|
||||||
|
|
||||||
pub struct LocalListener {
|
pub struct LocalListener {
|
||||||
listener: UnixListener,
|
listener: UnixListener,
|
||||||
|
@ -35,7 +35,7 @@ libssh-rs = {version="0.3.2", features=["vendored"], optional = true}
|
|||||||
#libssh-rs = {path="../../libssh-rs/libssh-rs", features=["vendored"], optional = true}
|
#libssh-rs = {path="../../libssh-rs/libssh-rs", features=["vendored"], optional = true}
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
socket2 = "0.5"
|
socket2 = "0.5"
|
||||||
uds_windows = "1.1.0"
|
wezterm-uds = { path = "../wezterm-uds" }
|
||||||
|
|
||||||
# Not used directly, but is used to centralize the openssl vendor feature selection
|
# Not used directly, but is used to centralize the openssl vendor feature selection
|
||||||
async_ossl = { path = "../async_ossl" }
|
async_ossl = { path = "../async_ossl" }
|
||||||
|
@ -827,15 +827,14 @@ impl SessionInner {
|
|||||||
.identity_agent()
|
.identity_agent()
|
||||||
.ok_or_else(|| anyhow!("no identity agent in config"))?;
|
.ok_or_else(|| anyhow!("no identity agent in config"))?;
|
||||||
let mut fd = {
|
let mut fd = {
|
||||||
|
use wezterm_uds::UnixStream;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use std::os::unix::net::UnixStream;
|
|
||||||
FileDescriptor::new(UnixStream::connect(&identity_agent)?)
|
FileDescriptor::new(UnixStream::connect(&identity_agent)?)
|
||||||
}
|
}
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
unsafe {
|
unsafe {
|
||||||
use std::os::windows::io::{FromRawSocket, IntoRawSocket};
|
use std::os::windows::io::{FromRawSocket, IntoRawSocket};
|
||||||
use uds_windows::UnixStream;
|
|
||||||
FileDescriptor::from_raw_socket(
|
FileDescriptor::from_raw_socket(
|
||||||
UnixStream::connect(&identity_agent)?.into_raw_socket(),
|
UnixStream::connect(&identity_agent)?.into_raw_socket(),
|
||||||
)
|
)
|
||||||
|
12
wezterm-uds/Cargo.toml
Normal file
12
wezterm-uds/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "wezterm-uds"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
repository = "https://github.com/wez/wezterm"
|
||||||
|
description = "Portable unix domain sockets"
|
||||||
|
license = "MIT"
|
||||||
|
documentation = "https://docs.rs/wezterm-uds"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
async-io = "2.3"
|
||||||
|
uds_windows = "1.1"
|
141
wezterm-uds/src/lib.rs
Normal file
141
wezterm-uds/src/lib.rs
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
use std::io::{Read, Write};
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::net::UnixStream as StreamImpl;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use std::os::windows::io::{
|
||||||
|
AsRawSocket, AsSocket, BorrowedSocket, FromRawSocket, IntoRawSocket, RawSocket,
|
||||||
|
};
|
||||||
|
use std::path::Path;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use uds_windows::UnixStream as StreamImpl;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::net::UnixListener as ListenerImpl;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use uds_windows::UnixListener as ListenerImpl;
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
use std::os::unix::net::SocketAddr;
|
||||||
|
#[cfg(windows)]
|
||||||
|
use uds_windows::SocketAddr;
|
||||||
|
|
||||||
|
/// This wrapper makes UnixStream IoSafe on all platforms.
|
||||||
|
/// This isn't strictly needed on unix, because async-io
|
||||||
|
/// includes an impl for the std UnixStream, but on Windows
|
||||||
|
/// the uds_windows crate doesn't have an impl.
|
||||||
|
/// Here we define it for all platforms in the interest of
|
||||||
|
/// minimizing platform differences.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct UnixStream(StreamImpl);
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
impl AsFd for UnixStream {
|
||||||
|
fn as_fd(&self) -> BorrowedFd {
|
||||||
|
self.0.as_fd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
impl IntoRawFd for UnixStream {
|
||||||
|
fn into_raw_fd(self) -> RawFd {
|
||||||
|
self.0.into_raw_fd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
impl FromRawFd for UnixStream {
|
||||||
|
unsafe fn from_raw_fd(fd: RawFd) -> UnixStream {
|
||||||
|
UnixStream(StreamImpl::from_raw_fd(fd))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(unix)]
|
||||||
|
impl AsRawFd for UnixStream {
|
||||||
|
fn as_raw_fd(&self) -> RawFd {
|
||||||
|
self.0.as_raw_fd()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
impl IntoRawSocket for UnixStream {
|
||||||
|
fn into_raw_socket(self) -> RawSocket {
|
||||||
|
self.0.into_raw_socket()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
impl AsSocket for UnixStream {
|
||||||
|
fn as_socket(&self) -> BorrowedSocket {
|
||||||
|
self.0.as_socket()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
impl FromRawSocket for UnixStream {
|
||||||
|
unsafe fn from_raw_socket(socket: RawSocket) -> UnixStream {
|
||||||
|
UnixStream(StreamImpl::from_raw_socket(socket))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Read for UnixStream {
|
||||||
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize, std::io::Error> {
|
||||||
|
self.0.read(buf)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Write for UnixStream {
|
||||||
|
fn write(&mut self, buf: &[u8]) -> Result<usize, std::io::Error> {
|
||||||
|
self.0.write(buf)
|
||||||
|
}
|
||||||
|
fn flush(&mut self) -> Result<(), std::io::Error> {
|
||||||
|
self.0.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl async_io::IoSafe for UnixStream {}
|
||||||
|
|
||||||
|
impl UnixStream {
|
||||||
|
pub fn connect<P: AsRef<Path>>(path: P) -> std::io::Result<Self> {
|
||||||
|
Ok(Self(StreamImpl::connect(path)?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for UnixStream {
|
||||||
|
type Target = StreamImpl;
|
||||||
|
fn deref(&self) -> &StreamImpl {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::DerefMut for UnixStream {
|
||||||
|
fn deref_mut(&mut self) -> &mut StreamImpl {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct UnixListener(ListenerImpl);
|
||||||
|
|
||||||
|
impl UnixListener {
|
||||||
|
pub fn bind<P: AsRef<Path>>(path: P) -> std::io::Result<Self> {
|
||||||
|
Ok(Self(ListenerImpl::bind(path)?))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn accept(&self) -> std::io::Result<(UnixStream, SocketAddr)> {
|
||||||
|
let (stream, addr) = self.0.accept()?;
|
||||||
|
Ok((UnixStream(stream), addr))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn incoming(&self) -> impl Iterator<Item = std::io::Result<UnixStream>> + '_ {
|
||||||
|
self.0.incoming().map(|r| r.map(UnixStream))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::Deref for UnixListener {
|
||||||
|
type Target = ListenerImpl;
|
||||||
|
fn deref(&self) -> &ListenerImpl {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::ops::DerefMut for UnixListener {
|
||||||
|
fn deref_mut(&mut self) -> &mut ListenerImpl {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user