Started BufferedEsock: A task-based ``wrapper" around an ESock that buffers its input and output.

Fortune for rsh's current commit: Small blessing − 小吉
master
Avril 3 years ago
parent 5fa9bccc52
commit 271e861169
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -19,6 +19,7 @@ use bytes::Bytes;
use cancel::*; use cancel::*;
pub mod enc; pub mod enc;
pub mod pipe;
/// Details of a newly accepted raw socket peer. /// Details of a newly accepted raw socket peer.
/// ///

@ -0,0 +1,53 @@
//! Piping buffered data from a raw socket to `ESock`
//!
//! This exists because i'm too dumb to implement a functional AsyncRead/Write buffered wrapper stream :/
use super::*;
use std::{
io,
marker::{
Send, Sync,
Unpin,
PhantomData,
},
};
use tokio::sync::{
mpsc,
};
use enc::{
ESock,
ESockReadHalf,
ESockWriteHalf,
};
/// The default buffer size for `BufferedESock`.
pub const DEFAULT_BUFFER_SIZE: usize = 32;
/// Task-based buffered piping to/from encrypted sockets.
pub struct BufferedESock<W, R>
{
bufsz: usize,
_backing: PhantomData<ESock<W, R>>,
}
impl<W, R> BufferedESock<W, R>
where W: AsyncWrite + Unpin + Send + 'static,
R: AsyncRead + Unpin + Send + 'static
{
/// Create a new buffered ESock pipe with a specific buffer size
pub fn with_size(tx: W, rx: R, bufsz: usize) -> Self
{
//TODO: Spawn read+write buffer tasks
Self {
bufsz,
_backing: PhantomData,
}
}
/// Create a new buffered ESock pipe with the default buffer size (`DEFAULT_BUFFER_SIZE`).
#[inline] pub fn new(tx: W, rx: R) -> Self
{
Self::with_size(tx, rx, DEFAULT_BUFFER_SIZE)
}
}
Loading…
Cancel
Save