forked from mirror/async-std
split io::write into multiple files
Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>staging
parent
a90100962d
commit
4a2194f37c
@ -0,0 +1,21 @@
|
||||
use crate::future::Future;
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
|
||||
use futures_io::AsyncWrite;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct FlushFuture<'a, T: Unpin + ?Sized> {
|
||||
pub(crate) writer: &'a mut T,
|
||||
}
|
||||
|
||||
impl<T: AsyncWrite + Unpin + ?Sized> Future for FlushFuture<'_, T> {
|
||||
type Output = io::Result<()>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
Pin::new(&mut *self.writer).poll_flush(cx)
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
use crate::future::Future;
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
|
||||
use futures_io::AsyncWrite;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct WriteFuture<'a, T: Unpin + ?Sized> {
|
||||
pub(crate) writer: &'a mut T,
|
||||
pub(crate) buf: &'a [u8],
|
||||
}
|
||||
|
||||
impl<T: AsyncWrite + Unpin + ?Sized> Future for WriteFuture<'_, T> {
|
||||
type Output = io::Result<usize>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let buf = self.buf;
|
||||
Pin::new(&mut *self.writer).poll_write(cx, buf)
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
use crate::future::Future;
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
use std::mem;
|
||||
|
||||
use futures_io::AsyncWrite;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct WriteAllFuture<'a, T: Unpin + ?Sized> {
|
||||
pub(crate) writer: &'a mut T,
|
||||
pub(crate) buf: &'a [u8],
|
||||
}
|
||||
|
||||
impl<T: AsyncWrite + Unpin + ?Sized> Future for WriteAllFuture<'_, T> {
|
||||
type Output = io::Result<()>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let Self { writer, buf } = &mut *self;
|
||||
|
||||
while !buf.is_empty() {
|
||||
let n = futures_core::ready!(Pin::new(&mut **writer).poll_write(cx, buf))?;
|
||||
let (_, rest) = mem::replace(buf, &[]).split_at(n);
|
||||
*buf = rest;
|
||||
|
||||
if n == 0 {
|
||||
return Poll::Ready(Err(io::ErrorKind::WriteZero.into()));
|
||||
}
|
||||
}
|
||||
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
use crate::future::Future;
|
||||
use crate::task::{Context, Poll};
|
||||
|
||||
use std::io;
|
||||
use std::pin::Pin;
|
||||
use std::io::IoSlice;
|
||||
|
||||
use futures_io::AsyncWrite;
|
||||
|
||||
#[doc(hidden)]
|
||||
#[allow(missing_debug_implementations)]
|
||||
pub struct WriteVectoredFuture<'a, T: Unpin + ?Sized> {
|
||||
pub(crate) writer: &'a mut T,
|
||||
pub(crate) bufs: &'a [IoSlice<'a>],
|
||||
}
|
||||
|
||||
impl<T: AsyncWrite + Unpin + ?Sized> Future for WriteVectoredFuture<'_, T> {
|
||||
type Output = io::Result<usize>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let bufs = self.bufs;
|
||||
Pin::new(&mut *self.writer).poll_write_vectored(cx, bufs)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue