diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-01-22 12:50:41 +0800 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-03-02 21:29:23 +0800 |
| commit | 2fc9fa299a68b53277bead0909557c9b1a963702 (patch) | |
| tree | 42e7035cab720f1650be16c52a457326699476ee /src/ipc/mod.rs | |
| parent | 459196bb22c11ca2943546743f2e0c02d8ee5e05 (diff) | |
| download | mullvadvpn-2fc9fa299a68b53277bead0909557c9b1a963702.tar.xz mullvadvpn-2fc9fa299a68b53277bead0909557c9b1a963702.zip | |
Use ZeroMQ for IPC
Diffstat (limited to 'src/ipc/mod.rs')
| -rw-r--r-- | src/ipc/mod.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ipc/mod.rs b/src/ipc/mod.rs new file mode 100644 index 0000000000..26485f8260 --- /dev/null +++ b/src/ipc/mod.rs @@ -0,0 +1,35 @@ +pub mod zmq; + +/// The type signature for functions accepting messages from the server. +/// If the server fails in delivering the message for any reason it will +/// put the cause in the Err part of the `Result`. +pub type OnMessage<MessageType> = FnMut(Result<MessageType>) + Send + 'static; + +/// The server end of our Inter-Process Communcation implementation. +pub trait IpcServer { + type MessageType; + + /// Starts listening to incoming IPC connections on the specified port. + /// Messages are sent to the `on_message` callback. If anything went wrong + /// when reading or parsing the message, the message will be an `Err`. + /// NOTE that this does not apply to errors regarding whether the server + /// could start or not, those are returned directly by this function. + /// + /// This function is non-blocking and thus spawns a thread where it + /// listens to messages. + fn start(self, port: u16, on_message: Box<OnMessage<Self::MessageType>>) -> Result<()>; +} + +error_chain!{ + errors { + ReadFailure { + description("Could not read IPC message") + } + CouldNotStartServer { + description("Failed to start the IPC server") + } + InvalidMessage(message: Vec<u8>) { + description("The IPC server got a message it did not know how to handle") + } + } +} |
