Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions docs/server/configuration.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# Server configuration

`WireframeServer` provides a builder API for adjusting runtime behaviour. This
guide focuses on tuning the exponential backoff used when accepting connections
fails.
`WireframeServer` provides a builder API for adjusting runtime behaviour. The
server employs a typestate (from `Unbound` to `Bound`) to ensure that binding
occurs before runtime: unbound servers do not expose `run` methods. This guide
focuses on tuning the exponential backoff used when accepting connections fails.

```rust,no_run
use wireframe::{app::WireframeApp, server::WireframeServer};

# #[tokio::main]
# async fn main() -> Result<(), wireframe::server::ServerError> {
let server = WireframeServer::new(|| WireframeApp::default())
.bind(([127, 0, 0, 1], 0).into())?;
server.run().await?;
# Ok(())
# }
```

## Accept loop backoff

Expand Down
8 changes: 6 additions & 2 deletions src/server/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
//! TCP binding is provided via the [`binding`](self::binding) module; preamble
//! behaviour is customized via the [`preamble`](self::preamble) module. The
//! server may be constructed unbound and later bound using
//! [`bind`](WireframeServer::bind) or
//! [`bind_existing_listener`](WireframeServer::bind_existing_listener) on [`Unbound`] servers.
//! [`bind`](super::WireframeServer::bind) or
//! [`bind_existing_listener`](super::WireframeServer::bind_existing_listener) on
//! [`Unbound`](super::Unbound) servers. The `run` methods are available only once
//! the server is [`Bound`](super::Bound), enforcing at compile time that the
//! binding step
//! cannot be skipped.

use core::marker::PhantomData;

Expand Down
32 changes: 32 additions & 0 deletions src/server/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,22 @@ where
/// # }
/// ```
///
/// Attempting to run a server without binding fails to compile:
///
/// Binding specifies the network address for the server to listen on.
/// It is required so the server knows where to accept incoming connections.
///
/// ```compile_fail
/// use wireframe::{app::WireframeApp, server::WireframeServer};
///
/// async fn try_run() {
/// WireframeServer::new(|| WireframeApp::default())
/// .run()
/// .await
/// .expect("unbound servers do not expose run()");
/// }
/// ```
///
Comment thread
coderabbitai[bot] marked this conversation as resolved.
/// # Errors
///
/// Returns a [`ServerError`] if runtime initialisation fails.
Expand Down Expand Up @@ -113,6 +129,22 @@ where
/// # }
/// ```
///
/// Attempting to run a server without binding fails to compile:
///
/// Binding specifies the network address for the server to listen on.
/// It is required so the server knows where to accept incoming connections.
///
/// ```compile_fail
/// use wireframe::{app::WireframeApp, server::WireframeServer};
///
/// async fn try_run_with_shutdown() {
/// WireframeServer::new(|| WireframeApp::default())
/// .run_with_shutdown(async {})
/// .await
/// .expect("unbound servers do not expose run_with_shutdown()");
/// }
/// ```
///
/// # Errors
///
/// Returns a [`ServerError`] if runtime initialisation fails.
Expand Down
Loading