Struct Server

Source
pub struct Server<T: AsyncRead + AsyncWrite, C: Encoder + Decoder, I> { /* private fields */ }
Expand description

Server provides a generic base for building stream servers.

This is generic over T, a stream reader and writer, C, and encoder and decoder, and I, and information object.

You probably want to be looking at TcpServer and UnixServer implementations

Implementations§

Source§

impl<T, C, I> Server<T, C, I>
where T: AsyncWrite + AsyncRead + Send + Sync + 'static, C: Encoder + Decoder + Clone + Send + 'static, I: Clone + Send + Debug + 'static, <C as Decoder>::Item: Clone + Send + Debug, <C as Decoder>::Error: Send + Debug, <C as Encoder>::Item: Clone + Send + Debug, <C as Encoder>::Error: Send + Debug,

Source

pub fn base(codec: C) -> Server<T, C, I>

Create a new base server with defined request and response message types.

This sets up internal resources however requires implementation to handle creating listeners and binding connections See TcpServer and UnixServer for examples

Source

pub fn incoming(&mut self) -> Option<UnboundedReceiver<Request<T, C, I>>>

Take the incoming data handle.

You can then use for_each to iterate over received requests as in the examples

Source

pub fn bind(&mut self, info: I, socket: T)

Bind a socket to a server.

This attaches an rx handler to the server, and can be used both for server listener implementations as well as to support server-initialised connections if required

Source

pub fn close(self)

Close the socket server

This sends exit messages to the main task and all connected hosts

Source§

impl<C> Server<TcpStream, C, TcpInfo>
where C: Encoder + Decoder + Clone + Send + 'static, <C as Decoder>::Item: Clone + Send + Debug, <C as Decoder>::Error: Send + Debug, <C as Encoder>::Item: Clone + Send + Debug, <C as Encoder>::Error: Send + Debug,

TCP server implementation.

Source

pub fn new(address: &SocketAddr, codec: C) -> Result<TcpServer<C>, Error>

Source

pub fn connect( &mut self, address: SocketAddr, ) -> impl Future<Item = (), Error = Error>

Source§

impl<C> Server<UnixStream, C, UnixInfo>
where C: Encoder + Decoder + Clone + Send + 'static, <C as Decoder>::Item: Clone + Send + Debug, <C as Decoder>::Error: Send + Debug, <C as Encoder>::Item: Clone + Send + Debug, <C as Encoder>::Error: Send + Debug,

Unix server implementation

This binds to and listens on a unix domain socket

Source

pub fn new(path: &str, codec: C) -> Result<UnixServer<C>, Error>

Source

pub fn shutdown(&self)

Trait Implementations§

Source§

impl<T, C, I> Clone for Server<T, C, I>
where T: AsyncWrite + AsyncRead + Send + Sync + 'static, C: Encoder + Decoder + Clone + Send + 'static, I: Clone + Send + Debug + 'static, <C as Decoder>::Item: Clone + Send + Debug, <C as Decoder>::Error: Send + Debug, <C as Encoder>::Item: Clone + Send + Debug, <C as Encoder>::Error: Send + Debug,

Clone over generic connector

All instances of a given connector contain the same arc/mutex protected information

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<T, C, I> Freeze for Server<T, C, I>
where C: Freeze,

§

impl<T, C, I> RefUnwindSafe for Server<T, C, I>

§

impl<T, C, I> Send for Server<T, C, I>
where C: Send, I: Send, <C as Decoder>::Item: Send,

§

impl<T, C, I> Sync for Server<T, C, I>
where C: Sync, I: Sync + Send, <C as Decoder>::Item: Send,

§

impl<T, C, I> Unpin for Server<T, C, I>
where C: Unpin, I: Unpin,

§

impl<T, C, I> UnwindSafe for Server<T, C, I>
where C: UnwindSafe, I: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.