pub struct Server<State> { /* private fields */ }Expand description
Serve an App over HTTP or HTTPS.
Implementations§
source§impl<State> Server<State>
impl<State> Server<State>
sourcepub fn listen<A: ToSocketAddrs>(
self,
address: A,
) -> impl Future<Output = Result<(), Error>>
pub fn listen<A: ToSocketAddrs>( self, address: A, ) -> impl Future<Output = Result<(), Error>>
Starts the server and listens for incoming connections at the provided address. Returns a future that resolves when the server is shutdown.
§Errors
If the server fails to bind to the provided address or is unable to finish serving all of the inflight connections within the specified shutdown timeout when a shutdown signal is received.
sourcepub fn shutdown_timeout(self, timeout: u64) -> Self
pub fn shutdown_timeout(self, timeout: u64) -> Self
Set the amount of time in seconds that the server will wait for inflight connections to complete before shutting down. The default value is 30 seconds.
sourcepub fn max_connections(self, n: usize) -> Self
pub fn max_connections(self, n: usize) -> Self
Sets the maximum number of concurrent connections that the server can accept. The default value is 256.
We suggest not setting this value unless you know what you are doing and have a good reason to do so. If you are unsure, it is best to leave this value at the default and scale horizontally.
If you do set this value, we suggest doing so by profiling the stack size
of your application when it’s under load and incrementally increasing
this value until you find a balance between performance and worry-free
programming. In other words, the closer this value is to the limit based
on your application’s stack consumption and the stack size of your server,
the more careful you will need to be when allocating values on the stack
(i.e dereferencing a heap pointer). Otherwise, you may encounter a stack
overflow. In addition to the stack size, you should also consider not
setting this value higher than the number of available file descriptors
(or ulimit -n) on POSIX systems.