Fortune for rsh's current commit: Small blessing − 小吉master
parent
5fa9bccc52
commit
271e861169
@ -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…
Reference in new issue