Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
e9c454edaf | |||
0c5cea017b | |||
25d0d3c79c | |||
ee34bec71a | |||
d71d40d582 | |||
89ffe98bc0 |
2 changed files with 31 additions and 24 deletions
13
doc/draft.md
13
doc/draft.md
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue