Fortune for rsh's current commit: Future small blessing − 末小吉sock-buffering
parent
f8b6e3a0c6
commit
69d546d2d1
@ -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…
Reference in new issue