run

Function run 

Source
pub async fn run<T>(
    listener: impl Listener,
    callbacks: Callbacks<T>,
    config: Config,
    shutdown: impl Future,
) -> Result<()>
where T: Send + 'static,
Expand description

Runs a milter that handles MTA connections until it is shut down.

While the future returned by run is awaited, it perpetually accepts new MTA connections and spawns a session task for each connection. This procedure continues and the future will not complete until the supplied shutdown future completes.

§Termination

For graceful termination, the milter task should be shut down by letting the shutdown future complete. If instead the future returned by run is simply dropped, currently active, spawned sessions may continue to execute.

When the shutdown future completes, all sessions exit cleanly as soon as possible: That is, any milter command in the act of being processed will be processed to completion (including the callback call), but commands waiting in the queue are dropped.

§Errors

When the listener fails to accept any new connections an error is returned. Else, the task runs for ever until it is shut down.

§Examples

The following example shows the simplest possible, no-op milter.

use indymilter::Callbacks;
use std::future;
use tokio::net::TcpListener;

let listener = TcpListener::bind("127.0.0.1:3000").await?;
let callbacks = Callbacks::<()>::new();
let config = Default::default();
let shutdown = future::pending::<()>();

indymilter::run(listener, callbacks, config, shutdown).await