[][src]Struct qrpc_sdk::RpcSocket

pub struct RpcSocket { /* fields omitted */ }

A qrpc connection wrapper

This type wraps a UNIX socket connection to a remote client. By default it is configured in client-only mode, meaning that the only time it listens for incoming messages is when waiting for a reply from the rpc broker, libqaul, or another service. To pro-actively reply to incoming requests (for example, if you want that your service can be used by other services)

Implementations

impl RpcSocket[src]

pub fn new<P: AsRef<Path>>(path: P) -> Result<Arc<Self>>[src]

Connect to an established socket to the RPC system

To listen for new connections you need to explicitly call listen(...), otherwise it will only act as a sending socket, where each reply is meant for one request.

pub fn create<P, F>(path: P, handle_connection: F) -> Result<Arc<Self>> where
    P: AsRef<Path>,
    F: Fn(Socket, SockAddr) + Send + Sync + 'static, 
[src]

Create a new QRPC socket. This function is meant for servers

Because creating the socket is synonymous with listening for connections on it, this function wraps both new (sort of), and listen, meaning that you must provide a closure at this point.

pub fn with_duration<P: AsRef<Path>>(
    path: P,
    timeout: Duration
) -> Result<Arc<Self>>
[src]

Create a new socket with an explicit timeout duration

Setup is the same as when calling new, except that you can choose an explicit timeout, instead of the default.

pub fn listen<F>(self: &Arc<Self>, fut: F) where
    F: Future<Output = ()> + Send + 'static, 
[src]

Start listening for connections with a future

Incoming messages need to be parsed by your service, and then replied to.

pub async fn send_msg<'s, F: 'static, T, S, M: 's>(
    self: &'s Arc<Self>,
    target: S,
    msg: Vec<u8>,
    handle: F
) -> RpcResult<T> where
    F: Fn(MsgReader<'s, M>) -> RpcResult<T> + Send,
    S: Into<String>,
    M: FromPointerReader<'s>, 
[src]

Send a binary payload message to a specific service.

This function needs to be called by your service when mapping your public API to the RPC layer. Internally all requests will be proxied, and parsed by your service backend.

Use the message builder functions available in io to construct a correctly packed and compressed message.

In order to react to the response sent by the other side, you need to provide a future to be run.

pub fn running(&self) -> bool[src]

Check if the socket is still running

Use this function in your service's listening code to determine whether the connection should be shut-down

pub fn listening(&self) -> bool[src]

Query whether this socket is listening for connections

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.