You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
//! 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)
|
|
}
|
|
}
|