Minor remote server cleanup
This commit is contained in:
parent
6ce1403aec
commit
84c243576f
3 changed files with 12 additions and 21 deletions
|
@ -51,6 +51,16 @@ pub async fn write_message<S: AsyncWrite + Unpin>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn write_size_prefixed_buffer<S: AsyncWrite + Unpin>(
|
||||||
|
stream: &mut S,
|
||||||
|
buffer: &mut Vec<u8>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let len = buffer.len() as u32;
|
||||||
|
stream.write_all(len.to_le_bytes().as_slice()).await?;
|
||||||
|
stream.write_all(buffer).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn read_message_raw<S: AsyncRead + Unpin>(
|
pub async fn read_message_raw<S: AsyncRead + Unpin>(
|
||||||
stream: &mut S,
|
stream: &mut S,
|
||||||
buffer: &mut Vec<u8>,
|
buffer: &mut Vec<u8>,
|
||||||
|
|
|
@ -53,7 +53,7 @@ use util::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SshSocket {
|
struct SshSocket {
|
||||||
connection_options: SshConnectionOptions,
|
connection_options: SshConnectionOptions,
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
socket_path: PathBuf,
|
socket_path: PathBuf,
|
||||||
|
@ -1370,12 +1370,6 @@ impl ConnectionPool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<SshRemoteClient> for AnyProtoClient {
|
|
||||||
fn from(client: SshRemoteClient) -> Self {
|
|
||||||
AnyProtoClient::new(client.client)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait(?Send)]
|
#[async_trait(?Send)]
|
||||||
trait RemoteConnection: Send + Sync {
|
trait RemoteConnection: Send + Sync {
|
||||||
fn start_proxy(
|
fn start_proxy(
|
||||||
|
|
|
@ -762,34 +762,21 @@ where
|
||||||
R: AsyncRead + Unpin,
|
R: AsyncRead + Unpin,
|
||||||
W: AsyncWrite + Unpin,
|
W: AsyncWrite + Unpin,
|
||||||
{
|
{
|
||||||
use remote::protocol::read_message_raw;
|
use remote::protocol::{read_message_raw, write_size_prefixed_buffer};
|
||||||
|
|
||||||
let mut buffer = Vec::new();
|
let mut buffer = Vec::new();
|
||||||
loop {
|
loop {
|
||||||
read_message_raw(&mut reader, &mut buffer)
|
read_message_raw(&mut reader, &mut buffer)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("failed to read message from {}", socket_name))?;
|
.with_context(|| format!("failed to read message from {}", socket_name))?;
|
||||||
|
|
||||||
write_size_prefixed_buffer(&mut writer, &mut buffer)
|
write_size_prefixed_buffer(&mut writer, &mut buffer)
|
||||||
.await
|
.await
|
||||||
.with_context(|| format!("failed to write message to {}", socket_name))?;
|
.with_context(|| format!("failed to write message to {}", socket_name))?;
|
||||||
|
|
||||||
writer.flush().await?;
|
writer.flush().await?;
|
||||||
|
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn write_size_prefixed_buffer<S: AsyncWrite + Unpin>(
|
|
||||||
stream: &mut S,
|
|
||||||
buffer: &mut Vec<u8>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let len = buffer.len() as u32;
|
|
||||||
stream.write_all(len.to_le_bytes().as_slice()).await?;
|
|
||||||
stream.write_all(buffer).await?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn initialize_settings(
|
fn initialize_settings(
|
||||||
session: AnyProtoClient,
|
session: AnyProtoClient,
|
||||||
fs: Arc<dyn Fs>,
|
fs: Arc<dyn Fs>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue