Started `Buffered<T, const SIZE: usize>`: Static buffering stream wrapper for `ESock` syncing.

Fortune for rsh's current commit: Future small blessing − 末小吉
sock-buffering
Avril 3 years ago
parent f8b6e3a0c6
commit 69d546d2d1
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -17,7 +17,7 @@ mopa = "0.2.2"
pin-project = "1.0.8"
serde = { version = "1.0.126", features = ["derive"] }
serde_cbor = "0.11.1"
smallvec = { version = "1.6.1", features = ["union", "serde", "write"] }
smallvec = { version = "1.6.1", features = ["union", "serde", "write", "const_generics"] }
stackalloc = "1.1.1"
tokio = { version = "0.2", features = ["full"] }
tokio-uring = "0.1.0"

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

@ -0,0 +1,50 @@
//! Stream buffering for sync of encrypted socked.
use super::*;
use smallvec::SmallVec;
use std::io;
use std::{
task::{
Poll, Context,
},
pin::Pin,
};
use bytes::{
Buf, BufMut,
};
/// A wrapping buffer over a writer and/or reader.
#[pin_project]
#[derive(Debug)]
pub struct Buffered<T: ?Sized, const SIZE: usize>
{
error: Option<io::Error>,
/// If an error has been set above and/or released from the above slot, set this to true.
/// Then all subsequent reads or writes will return a new error.
poisoned: bool,
buffer: SmallVec<[u8; SIZE]>, //TODO: Can we have a non-spilling stack vec?
#[pin] stream: T
}
impl<T: ?Sized + AsyncWrite, const SIZE: usize> AsyncWrite for Buffered<T, SIZE>
{
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize, io::Error>> {
// TODO: Push `buf` into `self.buffer`. When `self.buffer` is full, write to `self.stream` and clear what's been written.
todo!()
}
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
todo!("Flush any remaining bytes in the buffer to `stream`")
}
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), io::Error>> {
// I think we're supposed to imply flush here?
/*
(&mut self).poll_flush(cx)?;
let this = self.project();
this.stream.poll_flush(cx)?;
this.stream.poll_shutdown(cx)
*/
todo!("How to do the above?")
}
}
Loading…
Cancel
Save