Compare commits

...

6 commits
main ... r&d

Author SHA1 Message Date
Quentin e9c454edaf
The problem does not occure on the first service 2022-06-03 15:41:40 +02:00
Quentin 0c5cea017b
Simple example 2022-06-03 14:32:10 +02:00
Quentin 25d0d3c79c
Merge remote-tracking branch 'origin/main' into r&d 2022-06-03 14:28:50 +02:00
Quentin ee34bec71a
fix 2022-05-20 16:29:43 +02:00
Quentin d71d40d582
Improve draft 2022-05-19 10:21:14 +02:00
Quentin 89ffe98bc0
Changes to doc + example 2022-05-19 10:18:25 +02:00
2 changed files with 31 additions and 24 deletions

View file

@ -7,9 +7,22 @@ This example is meant to show basic service-based IMAP server with boitalettres
- [Source code](../examples/simple.rs)
```shell
$ export RUST_LOG="info,simple=trace,boitalettres=trace"
$ export RUSTFLAGS="--cfg tokio_unstable"
$ cargo run --example simple
```
- Test it manually
Theoretically, IMAP server expected end of lines with `\r\n` but implementations are more liberal.
To check with `\r\n`, use the `socat` command line.
The `nc` command line will send only `\n` when run on Linux, our current implementation supports it.
```
$ socat readline tcp4:127.0.0.1:4567,crnl
$ nc 127.0.0.1 4567
```
If you want to trace this `simple` example with the [`tokio-console`](https://github.com/tokio-rs/console/tree/main/tokio-console) utility, run:
```shell

View file

@ -3,12 +3,20 @@ use miette::{IntoDiagnostic, Result};
use boitalettres::proto::{Request, Response};
use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
use boitalettres::server::Server;
use tracing_subscriber;
use tokio::time::{sleep, Duration};
async fn handle_req(req: Request) -> Result<Response> {
use imap_codec::types::response::{Capability, Data};
tracing::debug!("Got request: {:#?}", req);
println!("WILL SLEEP");
sleep(Duration::from_millis(100)).await;
println!("DONE SLEEP");
let capabilities = vec![Capability::Imap4Rev1, Capability::Idle];
let body = vec![Data::Capability(capabilities)];
@ -17,7 +25,7 @@ async fn handle_req(req: Request) -> Result<Response> {
#[tokio::main]
async fn main() -> Result<()> {
setup_logging();
tracing_subscriber::fmt::init();
let incoming = AddrIncoming::new("127.0.0.1:4567")
.await
@ -25,10 +33,17 @@ async fn main() -> Result<()> {
let make_service = tower::service_fn(|addr: &AddrStream| {
tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
async {
let service = tower::ServiceBuilder::new().service_fn(handle_req);
println!("222 WILL SLEEP");
sleep(Duration::from_millis(100)).await;
println!("222 DONE SLEEP");
futures::future::ok::<_, std::convert::Infallible>(service)
let service = tower::ServiceBuilder::new().service_fn(handle_req);
let r: Result<_, boitalettres::errors::Error> = Ok(service);
r
}
});
let server = Server::new(incoming).serve(make_service);
@ -36,24 +51,3 @@ async fn main() -> Result<()> {
server.await.map_err(Into::into)
}
// Don't mind this, this is just for debugging.
fn setup_logging() {
use tracing_subscriber::prelude::*;
let registry = tracing_subscriber::registry().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),
),
);
#[cfg(tokio_unstable)]
let registry = registry.with(console_subscriber::spawn());
registry.init();
}