Struct fizyr_rpc::Listener

source ·
pub struct Listener<Socket>
where Socket: ListeningSocket,
{ /* private fields */ }
Expand description

Listener that spawns peers for all accepted connections.

Implementations§

source§

impl<Socket: ListeningSocket> Listener<Socket>

source

pub fn new(listener: Socket, config: Socket::Config) -> Self

Create a server on a listening socket.

The passed in config is used to create transports and peers for all accepted connections.

source

pub async fn bind<'a, Address: 'a>( address: Address, config: Socket::Config ) -> Result<Self>
where Socket: Bind<'a, Address>,

Create a server with a new listening socket bound to the given address.

The type of address accepted depends on the listener. For internet transports such as TCP, the address must implement tokio::net::ToSocketAddrs. For unix transports, the address must implement AsRef<std::path::Path>.

This function is asynchronous because it may perform a DNS lookup for some address types.

source

pub async fn run<F, R>(&mut self, task: F) -> Result<()>
where F: FnMut(PeerHandle<Socket::Body>, Socket::TransportInfo) -> R, R: Future<Output = ()> + Send + 'static,

Run the server.

The server will accept connections in a loop and spawn a user task for each new peer.

source

pub async fn accept( &mut self ) -> Result<(PeerHandle<Socket::Body>, Socket::TransportInfo)>

Accept a connection and spawn a peer for it.

A Peer is spawned for the new connection, and a PeerHandle is returned to allow interaction with the peer.

Auto Trait Implementations§

§

impl<Socket> RefUnwindSafe for Listener<Socket>
where Socket: RefUnwindSafe, <Socket as ListeningSocket>::Config: RefUnwindSafe,

§

impl<Socket> Send for Listener<Socket>
where Socket: Send,

§

impl<Socket> Sync for Listener<Socket>
where Socket: Sync,

§

impl<Socket> Unpin for Listener<Socket>
where <Socket as ListeningSocket>::Config: Unpin,

§

impl<Socket> UnwindSafe for Listener<Socket>
where Socket: UnwindSafe, <Socket as ListeningSocket>::Config: 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> 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>,

§

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>,

§

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.