summaryrefslogtreecommitdiffhomepage
path: root/talpid_ipc
diff options
context:
space:
mode:
Diffstat (limited to 'talpid_ipc')
-rw-r--r--talpid_ipc/src/http_ipc/connection_info.rs10
-rw-r--r--talpid_ipc/src/http_ipc/mod.rs25
-rw-r--r--talpid_ipc/src/nop_ipc.rs2
-rw-r--r--talpid_ipc/src/zmq_ipc.rs20
-rw-r--r--talpid_ipc/tests/zmq_integration_tests.rs8
5 files changed, 38 insertions, 27 deletions
diff --git a/talpid_ipc/src/http_ipc/connection_info.rs b/talpid_ipc/src/http_ipc/connection_info.rs
index 99d87c0603..1c4b3fac32 100644
--- a/talpid_ipc/src/http_ipc/connection_info.rs
+++ b/talpid_ipc/src/http_ipc/connection_info.rs
@@ -22,11 +22,13 @@ pub fn write(connection_info: &str) -> Result<()> {
let file_location = PathBuf::from(IPC_CONNECTION_INFO_FILE);
let mut file = open_file(&file_location)?;
let res = file.write_all(connection_info.as_bytes())
- .chain_err(|| ErrorKind::WriteConnectionInfoFailed(file_location.clone()));
+ .chain_err(|| ErrorKind::WriteConnectionInfoFailed(file_location.clone()),);
- debug!("Wrote IPC connection info ({}) to {}",
- connection_info,
- file_location.to_string_lossy());
+ debug!(
+ "Wrote IPC connection info ({}) to {}",
+ connection_info,
+ file_location.to_string_lossy()
+ );
res
}
diff --git a/talpid_ipc/src/http_ipc/mod.rs b/talpid_ipc/src/http_ipc/mod.rs
index 74b4feadef..16195ee69f 100644
--- a/talpid_ipc/src/http_ipc/mod.rs
+++ b/talpid_ipc/src/http_ipc/mod.rs
@@ -1,8 +1,8 @@
extern crate jsonrpc_core;
extern crate jsonrpc_http_server;
-use self::jsonrpc_http_server::{ServerBuilder, Server};
-use std::net::{SocketAddr, IpAddr, Ipv4Addr};
+use self::jsonrpc_http_server::{Server, ServerBuilder};
+use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::result::Result as StdResult;
mod connection_info;
@@ -36,8 +36,11 @@ impl ServerHandle {
pub fn start(build_router: fn() -> jsonrpc_core::IoHandler) -> Result<ServerHandle> {
let server = start_server(build_router).chain_err(|| ErrorKind::UnableToStartServer)?;
- let write_result = connection_info::write(server.address())
- .chain_err(|| ErrorKind::FailedToWriteConnectionInfo);
+ let write_result = connection_info::write(server.address()).chain_err(
+ || {
+ ErrorKind::FailedToWriteConnectionInfo
+ },
+ );
if let Err(e) = write_result {
error!("Could not write the connection info, killing the IPC server");
server.stop();
@@ -68,10 +71,12 @@ fn start_server_on_port(port: u16,
ServerBuilder::new(router)
.allow_only_bind_host()
.start_http(&listen_addr)
- .map(|server| {
- ServerHandle {
- address: format!("http://{}", listen_addr),
- server: server,
- }
- })
+ .map(
+ |server| {
+ ServerHandle {
+ address: format!("http://{}", listen_addr),
+ server: server,
+ }
+ },
+ )
}
diff --git a/talpid_ipc/src/nop_ipc.rs b/talpid_ipc/src/nop_ipc.rs
index 50d4fae791..f6ead2676b 100644
--- a/talpid_ipc/src/nop_ipc.rs
+++ b/talpid_ipc/src/nop_ipc.rs
@@ -1,4 +1,4 @@
-use super::{ErrorKind, Result, IpcServerId};
+use super::{ErrorKind, IpcServerId, Result};
use serde;
diff --git a/talpid_ipc/src/zmq_ipc.rs b/talpid_ipc/src/zmq_ipc.rs
index 24d8e2f5d1..49aad9f699 100644
--- a/talpid_ipc/src/zmq_ipc.rs
+++ b/talpid_ipc/src/zmq_ipc.rs
@@ -1,7 +1,7 @@
extern crate zmq;
extern crate serde_json;
-use super::{ErrorKind, Result, ResultExt, IpcServerId};
+use super::{ErrorKind, IpcServerId, Result, ResultExt};
use serde;
@@ -43,12 +43,15 @@ fn start_receive_loop<T, F>(socket: zmq::Socket, mut on_message: F) -> thread::J
where T: serde::Deserialize + 'static,
F: FnMut(Result<T>) + Send + 'static
{
- thread::spawn(move || loop {
- let read_res = socket.recv_bytes(0)
- .chain_err(|| ErrorKind::ReadFailure)
- .and_then(|a| parse_message(&a));
- on_message(read_res);
- })
+ thread::spawn(
+ move || loop {
+ let read_res = socket
+ .recv_bytes(0)
+ .chain_err(|| ErrorKind::ReadFailure)
+ .and_then(|a| parse_message(&a));
+ on_message(read_res);
+ },
+ )
}
fn parse_message<T>(message: &[u8]) -> Result<T>
@@ -100,7 +103,8 @@ impl<T> IpcClient<T>
let ctx = zmq::Context::new();
let socket = ctx.socket(zmq::PUSH)
.chain_err(|| "Could not create ZeroMQ PUSH socket".to_owned())?;
- socket.connect(&self.server_id)
+ socket
+ .connect(&self.server_id)
.chain_err(|| format!("Could not connect to {:?}", self.server_id))?;
self.socket = Some(socket);
diff --git a/talpid_ipc/tests/zmq_integration_tests.rs b/talpid_ipc/tests/zmq_integration_tests.rs
index ba22e28c40..4bd484cf0a 100644
--- a/talpid_ipc/tests/zmq_integration_tests.rs
+++ b/talpid_ipc/tests/zmq_integration_tests.rs
@@ -3,7 +3,7 @@ mod zmq_integration_tests {
extern crate serde;
extern crate talpid_ipc;
- use self::talpid_ipc::{Result, IpcServerId, IpcClient};
+ use self::talpid_ipc::{IpcClient, IpcServerId, Result};
use std::sync::mpsc::{self, Receiver};
use std::time::Duration;
@@ -16,7 +16,8 @@ mod zmq_integration_tests {
let msg = "Hello".to_owned();
ipc_client.send(&msg).expect("Could not send message");
- let message = new_messages_rx.recv_timeout(Duration::from_millis(1000))
+ let message = new_messages_rx
+ .recv_timeout(Duration::from_millis(1000))
.expect("Did not receive a message");
assert_eq!(message.unwrap(), "Hello", "Got wrong message");
@@ -29,8 +30,7 @@ mod zmq_integration_tests {
let callback = move |message: Result<T>| { let _ = tx.send(message); };
let connection_string =
- talpid_ipc::start_new_server(callback)
- .expect("Could not start the server");
+ talpid_ipc::start_new_server(callback).expect("Could not start the server");
(connection_string, rx)
}