summaryrefslogtreecommitdiffstats
path: root/third_party/rust/audioipc/src/rpc/mod.rs
blob: 8d54fc6e00f2a19ba59c7aefa9ee9a60f68d36c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// Copyright © 2017 Mozilla Foundation
//
// This program is made available under an ISC-style license.  See the
// accompanying file LICENSE for details

use futures::{Poll, Sink, Stream};
use std::io;

mod client;
mod driver;
mod server;

pub use self::client::{bind_client, Client, ClientProxy, Response};
pub use self::server::{bind_server, Server};

pub trait Handler {
    /// Message type read from transport
    type In;
    /// Message type written to transport
    type Out;
    type Transport: 'static
        + Stream<Item = Self::In, Error = io::Error>
        + Sink<SinkItem = Self::Out, SinkError = io::Error>;

    /// Mutable reference to the transport
    fn transport(&mut self) -> &mut Self::Transport;

    /// Consume a request
    fn consume(&mut self, message: Self::In) -> io::Result<()>;

    /// Produce a response
    fn produce(&mut self) -> Poll<Option<Self::Out>, io::Error>;

    /// RPC currently in flight
    fn has_in_flight(&self) -> bool;
}