sigio 0.1.0

signal-based async io
Documentation
use std::task::Waker;
use std::task::Poll;
use std::task::Context;
use std::io;
use std::pin::Pin;
use tokio::io::{ReadBuf, AsyncRead, AsyncWrite};
use crate::{File, poll_io};

impl tokio::io::AsyncRead for File {
	fn poll_read(
        self: Pin<&mut Self>,
        ctx: &mut Context<'_>,
        buf: &mut ReadBuf<'_>
    ) -> Poll<io::Result<()>> {
		let bbuf = buf.initialize_unfilled();
		poll_io(
			self.fd, ctx,
			self.raw_read(bbuf),
			|n| { buf.advance(n.try_into().unwrap()); })
	}
}

impl AsyncWrite for File {
    fn poll_write(
        self: Pin<&mut Self>,
        ctx: &mut Context<'_>,
        buf: &[u8]
    ) -> Poll<Result<usize, io::Error>> {
		poll_io(
			self.fd, ctx,
			self.raw_write(buf),
			|n| n.try_into().unwrap())
	}
    fn poll_flush(
        self: Pin<&mut Self>,
        ctx: &mut Context<'_>
    ) -> Poll<Result<(), io::Error>> {
		// raw file descriptors have no buffers
		Poll::Ready(Ok(()))
	}
    fn poll_shutdown(
        self: Pin<&mut Self>,
        ctx: &mut Context<'_>
    ) -> Poll<Result<(), io::Error>> {
		// cleanup is handled by Drop,
		// trying to handle it here would result in double close errors.
		Poll::Ready(Ok(()))
	}
}

// TODO: AsyncSeek