Minor remote server cleanup

This commit is contained in:
Max Brunsfeld 2025-08-22 16:21:46 -07:00
parent 6ce1403aec
commit 84c243576f
3 changed files with 12 additions and 21 deletions

View file

@ -51,6 +51,16 @@ pub async fn write_message<S: AsyncWrite + Unpin>(
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>(
stream: &mut S,
buffer: &mut Vec<u8>,

View file

@ -53,7 +53,7 @@ use util::{
};
#[derive(Clone)]
pub struct SshSocket {
struct SshSocket {
connection_options: SshConnectionOptions,
#[cfg(not(target_os = "windows"))]
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)]
trait RemoteConnection: Send + Sync {
fn start_proxy(

View file

@ -762,34 +762,21 @@ where
R: AsyncRead + 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();
loop {
read_message_raw(&mut reader, &mut buffer)
.await
.with_context(|| format!("failed to read message from {}", socket_name))?;
write_size_prefixed_buffer(&mut writer, &mut buffer)
.await
.with_context(|| format!("failed to write message to {}", socket_name))?;
writer.flush().await?;
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(
session: AnyProtoClient,
fs: Arc<dyn Fs>,