use super::Backend;
use crate::conn::{ConnConfig, Connection};
use crate::service::{H1Service, Upgraded};
use crate::write::DateCache;
use bytes::Bytes;
use std::cell::RefCell;
use std::io;
use std::net::SocketAddr;
use std::rc::Rc;
use tokio::io::{AsyncRead, AsyncWrite};
#[cfg_attr(feature = "hyper-backend", allow(dead_code))]
pub(crate) struct RcService<S>(pub(crate) Rc<S>);
impl<S: H1Service> H1Service for RcService<S> {
type Future = S::Future;
#[inline]
fn call(&self, req: crate::Request) -> Self::Future {
self.0.call(req)
}
}
#[cfg_attr(feature = "hyper-backend", allow(dead_code))]
pub(crate) struct NativeBackend;
impl Backend for NativeBackend {
async fn serve<IO, S>(
io: IO,
service: Rc<S>,
cfg: Rc<ConnConfig>,
date: Rc<RefCell<DateCache>>,
buffered: Bytes,
peer: Option<SocketAddr>,
) -> io::Result<Option<Upgraded>>
where
IO: AsyncRead + AsyncWrite + Unpin + 'static,
S: H1Service + 'static,
{
Connection::with_buffered(io, RcService(service), cfg, date, buffered)
.with_peer(peer)
.serve()
.await
}
}