diff options
| author | Linus Färnstrand <linus@mullvad.net> | 2017-06-08 09:54:54 +0200 |
|---|---|---|
| committer | Linus Färnstrand <linus@mullvad.net> | 2017-06-08 09:54:54 +0200 |
| commit | 85b477d93760fed42dd2fcfda9cdf3384fe7925d (patch) | |
| tree | 0833748ffa2940a946202c033918f31fe32b262c /talpid_ipc | |
| parent | c2aaa4eb26af015ef949785668751cded783675d (diff) | |
| download | mullvadvpn-85b477d93760fed42dd2fcfda9cdf3384fe7925d.tar.xz mullvadvpn-85b477d93760fed42dd2fcfda9cdf3384fe7925d.zip | |
Add CloseHandle to talpid_ipc
Diffstat (limited to 'talpid_ipc')
| -rw-r--r-- | talpid_ipc/Cargo.toml | 6 | ||||
| -rw-r--r-- | talpid_ipc/src/lib.rs | 31 |
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(); + } +} |
