pub struct ServerBuilder<W = NoWork, G = NoGate, S = NoopSink, T = NoTls> { /* private fields */ }Expand description
Builds a Server. A builder without a gate or without sessions/handler
has no build method: forgetting either is a compile error.
§Examples
use net_io::{AllowAll, DriverKind, Limits, ListenerSpec, ServerBuilder};
use std::time::{Duration, Instant};
let server = ServerBuilder::new()
.listener(ListenerSpec::tcp("0.0.0.0:8080").name("public"))
.listener(ListenerSpec::tcp("127.0.0.1:9090").name("admin"))
.driver(DriverKind::Blocking)
.workers(64)
.limits(Limits::builder().idle_timeout(Duration::from_secs(5)).build()?)
.handler(|conn| { conn.send_all(b"hello\n")?; Ok(()) })
.gate(AllowAll)
.build()?; // listeners bound, workers started, door closed
// ... drop privileges here ...
server.open_door()?;
let report = server.shutdown(Instant::now() + Duration::from_secs(30));
println!("{report:?}");Implementations§
Source§impl ServerBuilder
impl ServerBuilder
Sourcepub fn new() -> ServerBuilder
pub fn new() -> ServerBuilder
An empty builder.
Source§impl<W, G, S, T> ServerBuilder<W, G, S, T>
impl<W, G, S, T> ServerBuilder<W, G, S, T>
Sourcepub fn listener(self, spec: ListenerSpec) -> Self
pub fn listener(self, spec: ListenerSpec) -> Self
Adds a listener (at most 64).
Sourcepub fn driver(self, kind: DriverKind) -> Self
pub fn driver(self, kind: DriverKind) -> Self
The driver (default Auto).
Sourcepub fn workers(self, n: u16) -> Self
pub fn workers(self, n: u16) -> Self
Worker threads (default 128 on the blocking driver; 1 to 4,096).
Sourcepub fn limits(self, limits: Limits) -> Self
pub fn limits(self, limits: Limits) -> Self
The server’s limits; unset values take the driver’s defaults.
Sourcepub fn sessions<F: SessionFactory>(
self,
factory: F,
) -> ServerBuilder<Sessions<F>, G, S, T>
pub fn sessions<F: SessionFactory>( self, factory: F, ) -> ServerBuilder<Sessions<F>, G, S, T>
Runs a sans-IO session per connection.
Sourcepub fn handler<H>(
self,
handler: H,
) -> ServerBuilder<BlockingHandler<H>, G, S, T>
pub fn handler<H>( self, handler: H, ) -> ServerBuilder<BlockingHandler<H>, G, S, T>
Runs a blocking handler per connection (on the blocking driver).
Sourcepub fn gate<G2: Gate>(self, gate: G2) -> ServerBuilder<W, G2, S, T>
pub fn gate<G2: Gate>(self, gate: G2) -> ServerBuilder<W, G2, S, T>
The connection gate (required; AllowAll for none).
Sourcepub fn events<S2: EventSink>(self, sink: S2) -> ServerBuilder<W, G, S2, T>
pub fn events<S2: EventSink>(self, sink: S2) -> ServerBuilder<W, G, S2, T>
The event sink (default NoopSink).
Sourcepub fn control<C: ControlLine>(self, line: Arc<C>) -> Self
pub fn control<C: ControlLine>(self, line: Arc<C>) -> Self
The control line (default: none).
Sourcepub fn wipe_buffers(self, on: bool) -> Self
pub fn wipe_buffers(self, on: bool) -> Self
Zero the used part of every buffer when it returns to a pool (default on).
Source§impl<W, G, S, T> ServerBuilder<W, G, S, T>
impl<W, G, S, T> ServerBuilder<W, G, S, T>
Trait Implementations§
Source§impl Default for ServerBuilder
impl Default for ServerBuilder
Source§fn default() -> ServerBuilder
fn default() -> ServerBuilder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<W = NoWork, G = NoGate, S = NoopSink, T = NoTls> !RefUnwindSafe for ServerBuilder<W, G, S, T>
impl<W = NoWork, G = NoGate, S = NoopSink, T = NoTls> !UnwindSafe for ServerBuilder<W, G, S, T>
impl<W, G, S, T> Freeze for ServerBuilder<W, G, S, T>
impl<W, G, S, T> Send for ServerBuilder<W, G, S, T>
impl<W, G, S, T> Sync for ServerBuilder<W, G, S, T>
impl<W, G, S, T> Unpin for ServerBuilder<W, G, S, T>
impl<W, G, S, T> UnsafeUnpin for ServerBuilder<W, G, S, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more