diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-04-21 23:43:02 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-05-04 10:48:06 -0300 |
| commit | 2af6657beeaaf657d4c3c6996437934c6b61a86f (patch) | |
| tree | af90748ea2c9d2a2d9375559ec1c187290e7cebe /talpid-openvpn-plugin/src | |
| parent | c15036ad213c29ed0764b9fbe61f517cd604ac32 (diff) | |
| download | mullvadvpn-2af6657beeaaf657d4c3c6996437934c6b61a86f.tar.xz mullvadvpn-2af6657beeaaf657d4c3c6996437934c6b61a86f.zip | |
Reuse WebSocket connection in `WsIpcClient`
Diffstat (limited to 'talpid-openvpn-plugin/src')
| -rw-r--r-- | talpid-openvpn-plugin/src/processing.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/talpid-openvpn-plugin/src/processing.rs b/talpid-openvpn-plugin/src/processing.rs index b76e92e409..5fc2a1312e 100644 --- a/talpid-openvpn-plugin/src/processing.rs +++ b/talpid-openvpn-plugin/src/processing.rs @@ -1,5 +1,6 @@ use openvpn_plugin; use std::collections::HashMap; +use std::sync::Mutex; use talpid_ipc::{IpcServerId, WsIpcClient}; error_chain! { @@ -13,14 +14,17 @@ error_chain! { /// Struct processing OpenVPN events and notifies listeners over IPC pub struct EventProcessor { - ipc_client: WsIpcClient, + ipc_client: Mutex<WsIpcClient>, } impl EventProcessor { pub fn new(server_id: IpcServerId) -> Result<EventProcessor> { trace!("Creating EventProcessor"); - let ipc_client = WsIpcClient::new(server_id).chain_err(|| "Unable to create IPC client")?; - Ok(EventProcessor { ipc_client }) + let ipc_client = + WsIpcClient::connect(server_id).chain_err(|| "Unable to create IPC client")?; + Ok(EventProcessor { + ipc_client: Mutex::new(ipc_client), + }) } pub fn process_event( @@ -30,6 +34,8 @@ impl EventProcessor { ) -> Result<()> { trace!("Processing \"{:?}\" event", event); self.ipc_client + .lock() + .expect("a thread panicked while using the RPC client in the OpenVPN plugin") .call("openvpn_event", &(event, env)) .map(|_: Option<()>| ()) .chain_err(|| ErrorKind::IpcSendingError) |
