Compare commits
No commits in common. "05b5efc8bf21a5e8422ae29e874969afd8ad9869" and "1b3147d4936e15eee9f92699f12c490603d60721" have entirely different histories.
05b5efc8bf
...
1b3147d493
4 changed files with 11 additions and 36 deletions
|
@ -23,4 +23,3 @@ tower = { version = "0.4", features = ["full"] }
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
eyre = "0.6"
|
eyre = "0.6"
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
console-subscriber = "0.1"
|
|
||||||
|
|
|
@ -14,18 +14,15 @@ async fn handle_req(req: Request) -> eyre::Result<Response> {
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> eyre::Result<()> {
|
async fn main() -> eyre::Result<()> {
|
||||||
setup_logging();
|
tracing_subscriber::fmt()
|
||||||
|
.with_max_level(tracing::Level::TRACE)
|
||||||
|
.init();
|
||||||
|
|
||||||
let incoming = AddrIncoming::new("127.0.0.1:4567").await?;
|
let incoming = AddrIncoming::new("127.0.0.1:4567").await?;
|
||||||
|
|
||||||
let make_service = tower::service_fn(|addr: &AddrStream| {
|
let make_service = tower::service_fn(|addr: &AddrStream| {
|
||||||
tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
|
tracing::debug!("Accept: {} -> {}", addr.remote_addr, addr.local_addr);
|
||||||
|
futures::future::ok::<_, std::convert::Infallible>(tower::service_fn(handle_req))
|
||||||
let service = tower::ServiceBuilder::new()
|
|
||||||
.buffer(16)
|
|
||||||
.service_fn(handle_req);
|
|
||||||
|
|
||||||
futures::future::ok::<_, std::convert::Infallible>(service)
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let server = Server::new(incoming).serve(make_service);
|
let server = Server::new(incoming).serve(make_service);
|
||||||
|
@ -33,23 +30,3 @@ async fn main() -> eyre::Result<()> {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't mind this, this is just for debugging.
|
|
||||||
fn setup_logging() {
|
|
||||||
use tracing_subscriber::prelude::*;
|
|
||||||
|
|
||||||
tracing_subscriber::registry()
|
|
||||||
.with(console_subscriber::spawn())
|
|
||||||
.with(
|
|
||||||
tracing_subscriber::fmt::layer().with_filter(
|
|
||||||
tracing_subscriber::filter::Targets::new()
|
|
||||||
.with_default(tracing::Level::DEBUG)
|
|
||||||
.with_target("boitalettres", tracing::Level::TRACE)
|
|
||||||
.with_target("simple", tracing::Level::TRACE)
|
|
||||||
.with_target("tower", tracing::Level::TRACE)
|
|
||||||
.with_target("tokio_tower", tracing::Level::TRACE)
|
|
||||||
.with_target("mio", tracing::Level::TRACE),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.init();
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub enum Error<A> {
|
||||||
#[error("Error occured when accepting new connections")]
|
#[error("Error occured when accepting new connections")]
|
||||||
Accept(#[source] A),
|
Accept(#[source] A),
|
||||||
#[error("Error occured on service creation")]
|
#[error("Error occured on service creation")]
|
||||||
MakeService(#[source] tower::BoxError),
|
MakeService(#[source] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Default, Clone)]
|
#[derive(Debug, Default, Clone)]
|
||||||
|
@ -51,7 +51,7 @@ where
|
||||||
I: Accept,
|
I: Accept,
|
||||||
I::Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
I::Conn: AsyncRead + AsyncWrite + Unpin + Send + 'static,
|
||||||
S: MakeServiceRef<I::Conn, Request, Response = Response>,
|
S: MakeServiceRef<I::Conn, Request, Response = Response>,
|
||||||
S::MakeError: Into<tower::BoxError> + std::fmt::Display,
|
S::MakeError: Into<Box<dyn std::error::Error + Send + Sync + 'static>> + std::fmt::Display,
|
||||||
S::Error: std::fmt::Display,
|
S::Error: std::fmt::Display,
|
||||||
S::Future: Send + 'static,
|
S::Future: Send + 'static,
|
||||||
S::Service: Send + 'static,
|
S::Service: Send + 'static,
|
||||||
|
|
|
@ -8,8 +8,7 @@ use futures::stream::Stream;
|
||||||
|
|
||||||
use crate::proto::{Request, Response};
|
use crate::proto::{Request, Response};
|
||||||
|
|
||||||
type Error = tower::BoxError;
|
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
|
||||||
type Result<T, E = Error> = std::result::Result<T, E>;
|
|
||||||
|
|
||||||
#[pin_project::pin_project]
|
#[pin_project::pin_project]
|
||||||
pub struct Connection<C> {
|
pub struct Connection<C> {
|
||||||
|
@ -33,7 +32,7 @@ impl<C> Stream for Connection<C>
|
||||||
where
|
where
|
||||||
C: AsyncRead + Unpin,
|
C: AsyncRead + Unpin,
|
||||||
{
|
{
|
||||||
type Item = Result<Request>;
|
type Item = Result<Request, Error>;
|
||||||
|
|
||||||
fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
use imap_codec::parse::command::command as parse_command;
|
use imap_codec::parse::command::command as parse_command;
|
||||||
|
@ -76,7 +75,7 @@ impl<C> Connection<C>
|
||||||
where
|
where
|
||||||
C: AsyncWrite,
|
C: AsyncWrite,
|
||||||
{
|
{
|
||||||
fn poll_flush_buffer(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<Result<()>> {
|
fn poll_flush_buffer(self: Pin<&mut Self>, cx: &mut task::Context) -> Poll<Result<(), Error>> {
|
||||||
use bytes::Buf;
|
use bytes::Buf;
|
||||||
|
|
||||||
let mut this = self.project();
|
let mut this = self.project();
|
||||||
|
@ -90,7 +89,7 @@ where
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn send(&mut self, item: Response) -> Result<()> {
|
pub(crate) fn send(&mut self, item: Response) -> Result<(), Error> {
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
use imap_codec::codec::Encode;
|
use imap_codec::codec::Encode;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue