tokio_proto

Struct TcpServer

Source
pub struct TcpServer<Kind, P> { /* private fields */ }
Expand description

A builder for TCP servers.

Setting up a server needs, at minimum:

  • A server protocol implementation
  • An address
  • A service to provide

In addition to those basics, the builder provides some additional configuration, which is expected to grow over time.

See the crate docs for an example.

Implementations§

Source§

impl<Kind, P> TcpServer<Kind, P>
where P: BindServer<Kind, TcpStream> + Send + Sync + 'static,

Source

pub fn new(protocol: P, addr: SocketAddr) -> TcpServer<Kind, P>

Starts building a server for the given protocol and address, with default configuration.

Generally, a protocol is implemented not by implementing the BindServer trait directly, but instead by implementing one of the protocol traits:

  • pipeline::ServerProto
  • multiplex::ServerProto
  • streaming::pipeline::ServerProto
  • streaming::multiplex::ServerProto

See the crate documentation for more details on those traits.

Source

pub fn addr(&mut self, addr: SocketAddr)

Set the address for the server.

Source

pub fn threads(&mut self, threads: usize)

Set the number of threads running simultaneous event loops (Unix only).

Source

pub fn serve<S>(&self, new_service: S)
where S: NewService + Send + Sync + 'static, S::Instance: 'static, P::ServiceError: 'static, P::ServiceResponse: 'static, P::ServiceRequest: 'static, S::Request: From<P::ServiceRequest>, S::Response: Into<P::ServiceResponse>, S::Error: Into<P::ServiceError>,

Start up the server, providing the given service on it.

This method will block the current thread until the server is shut down.

Source

pub fn with_handle<F, S>(&self, new_service: F)
where F: Fn(&Handle) -> S + Send + Sync + 'static, S: NewService + Send + Sync + 'static, S::Instance: 'static, P::ServiceError: 'static, P::ServiceResponse: 'static, P::ServiceRequest: 'static, S::Request: From<P::ServiceRequest>, S::Response: Into<P::ServiceResponse>, S::Error: Into<P::ServiceError>,

Start up the server, providing the given service on it, and providing access to the event loop handle.

The new_service argument is a closure that is given an event loop handle, and produces a value implementing NewService. That value is in turn used to make a new service instance for each incoming connection.

This method will block the current thread until the server is shut down.

Trait Implementations§

Source§

impl<Kind: Debug, P: Debug> Debug for TcpServer<Kind, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Kind, P> Freeze for TcpServer<Kind, P>

§

impl<Kind, P> RefUnwindSafe for TcpServer<Kind, P>
where Kind: RefUnwindSafe, P: RefUnwindSafe,

§

impl<Kind, P> Send for TcpServer<Kind, P>
where Kind: Send, P: Sync + Send,

§

impl<Kind, P> Sync for TcpServer<Kind, P>
where Kind: Sync, P: Sync + Send,

§

impl<Kind, P> Unpin for TcpServer<Kind, P>
where Kind: Unpin,

§

impl<Kind, P> UnwindSafe for TcpServer<Kind, P>
where Kind: UnwindSafe, P: RefUnwindSafe,

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.