summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--talpid_ipc/Cargo.toml6
-rw-r--r--talpid_ipc/src/lib.rs31
2 files changed, 18 insertions, 19 deletions
diff --git a/talpid_ipc/Cargo.toml b/talpid_ipc/Cargo.toml
index d1a2bb13e2..630cb1ced1 100644
--- a/talpid_ipc/Cargo.toml
+++ b/talpid_ipc/Cargo.toml
@@ -9,12 +9,12 @@ error-chain = "0.10"
serde = "1.0"
serde_json = "1.0"
log = "0.3"
-jsonrpc-core = { git = "https://github.com/faern/jsonrpc", branch = "bind-zero" }
-jsonrpc-ws-server = { git = "https://github.com/faern/jsonrpc", branch = "bind-zero" }
+jsonrpc-core = { git = "https://github.com/faern/jsonrpc", branch = "ws-close-handle" }
+jsonrpc-ws-server = { git = "https://github.com/faern/jsonrpc", branch = "ws-close-handle" }
ws = { git = "https://github.com/tomusdrw/ws-rs" }
url = "1.4"
[dev-dependencies]
assert_matches = "1.0"
env_logger = "0.4"
-jsonrpc-macros = { git = "https://github.com/faern/jsonrpc", branch = "bind-zero" }
+jsonrpc-macros = { git = "https://github.com/faern/jsonrpc", branch = "ws-close-handle" }
diff --git a/talpid_ipc/src/lib.rs b/talpid_ipc/src/lib.rs
index f6d4acea19..3ef9bf4733 100644
--- a/talpid_ipc/src/lib.rs
+++ b/talpid_ipc/src/lib.rs
@@ -26,18 +26,6 @@ pub type IpcServerId = String;
error_chain!{
errors {
- ReadFailure {
- description("Could not read IPC message")
- }
- ParseFailure {
- description("Unable to serialize/deserialize message")
- }
- CouldNotStartServer {
- description("Failed to start the IPC server")
- }
- SendError {
- description("Unable to send message")
- }
IpcServerError {
description("Error in IPC server")
}
@@ -74,17 +62,28 @@ impl IpcServer {
.chain_err(|| ErrorKind::IpcServerError)
}
+ /// Returns the localhost address this `IpcServer` is listening on.
pub fn address(&self) -> &str {
&self.address
}
- /// Consumes the server, stops it and waits for it to finish.
- pub fn stop(self) {
- self.server.close();
+ /// Creates a handle bound to this `IpcServer` that can be used to shut it down.
+ pub fn close_handle(&self) -> CloseHandle {
+ CloseHandle(self.server.close_handle())
}
- /// Consumes the server and waits for it to finish.
+ /// Consumes the server and waits for it to finish. Get an `CloseHandle` before calling this
+ /// if you want to be able to shut the server down.
pub fn wait(self) -> Result<()> {
self.server.wait().chain_err(|| ErrorKind::IpcServerError)
}
}
+
+#[derive(Clone)]
+pub struct CloseHandle(jsonrpc_ws_server::CloseHandle);
+
+impl CloseHandle {
+ pub fn close(self) {
+ self.0.close();
+ }
+}