mirror of
https://github.com/sigoden/dufs.git
synced 2026-04-09 00:59:02 +03:00
32 lines
785 B
Rust
32 lines
785 B
Rust
use hyper::server::accept::Accept;
|
|
use tokio::net::UnixListener;
|
|
|
|
use std::pin::Pin;
|
|
use std::task::{Context, Poll};
|
|
|
|
pub struct UnixAcceptor {
|
|
inner: UnixListener,
|
|
}
|
|
|
|
impl UnixAcceptor {
|
|
pub fn from_listener(listener: UnixListener) -> Self {
|
|
Self { inner: listener }
|
|
}
|
|
}
|
|
|
|
impl Accept for UnixAcceptor {
|
|
type Conn = tokio::net::UnixStream;
|
|
type Error = std::io::Error;
|
|
|
|
fn poll_accept(
|
|
self: Pin<&mut Self>,
|
|
cx: &mut Context<'_>,
|
|
) -> Poll<Option<Result<Self::Conn, Self::Error>>> {
|
|
match self.inner.poll_accept(cx) {
|
|
Poll::Pending => Poll::Pending,
|
|
Poll::Ready(Ok((socket, _addr))) => Poll::Ready(Some(Ok(socket))),
|
|
Poll::Ready(Err(err)) => Poll::Ready(Some(Err(err))),
|
|
}
|
|
}
|
|
}
|