Struct Server

Source
pub struct Server { /* private fields */ }
Expand description

The main class of this library.

Destroying this object will immediately close the listening socket and the reading part of all the client’s connections. Requests that have already been returned by the recv() function will not close and the responses will be transferred to the client.

Implementations§

Source§

impl Server

Source

pub fn http<A>( addr: A, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
where A: ToSocketAddrs,

Shortcut for a simple server on a specific address.

Source

pub fn https<A>( addr: A, config: SslConfig, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
where A: ToSocketAddrs,

Shortcut for an HTTPS server on a specific address.

Source

pub fn http_unix( path: &Path, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>

Shortcut for a UNIX socket server at a specific path

Source

pub fn new( config: ServerConfig, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>

Builds a new server that listens on the specified address.

Source

pub fn from_listener<L: Into<Listener>>( listener: L, ssl_config: Option<SslConfig>, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>

Builds a new server using the specified TCP listener.

This is useful if you’ve constructed TcpListener using some less usual method such as from systemd. For other cases, you probably want the new() function.

Source

pub fn incoming_requests(&self) -> IncomingRequests<'_>

Returns an iterator for all the incoming requests.

The iterator will return None if the server socket is shutdown.

Source

pub fn server_addr(&self) -> ListenAddr

Returns the address the server is listening to.

Source

pub fn num_connections(&self) -> usize

Returns the number of clients currently connected to the server.

Source

pub fn recv(&self) -> IoResult<Request>

Blocks until an HTTP request has been submitted and returns it.

Source

pub fn recv_timeout(&self, timeout: Duration) -> IoResult<Option<Request>>

Same as recv() but doesn’t block longer than timeout

Source

pub fn try_recv(&self) -> IoResult<Option<Request>>

Same as recv() but doesn’t block.

Source

pub fn unblock(&self)

Unblock thread stuck in recv() or incoming_requests(). If there are several such threads, only one is unblocked. This method allows graceful shutdown of server.

Trait Implementations§

Source§

impl Drop for Server

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Server

§

impl RefUnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl UnwindSafe for Server

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.