diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-02-28 11:09:00 +0800 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-03-02 21:29:23 +0800 |
| commit | 2ce1865e915fef63ddc03b92bfe647e63e5bfd49 (patch) | |
| tree | 6d463984ea06842a5d0c24bb9eabb32011f9fd2c | |
| parent | 27c7a0f0a8b78756a92ec0ff1486164c649c3388 (diff) | |
| download | mullvadvpn-2ce1865e915fef63ddc03b92bfe647e63e5bfd49.tar.xz mullvadvpn-2ce1865e915fef63ddc03b92bfe647e63e5bfd49.zip | |
Remove the port from the public API
| -rw-r--r-- | talpid_ipc/src/ipc/mod.rs | 2 | ||||
| -rw-r--r-- | talpid_ipc/src/ipc/nop_ipc.rs | 2 | ||||
| -rw-r--r-- | talpid_ipc/src/ipc/zmq_ipc.rs | 27 |
3 files changed, 21 insertions, 10 deletions
diff --git a/talpid_ipc/src/ipc/mod.rs b/talpid_ipc/src/ipc/mod.rs index afb140f4c6..93130ee4ac 100644 --- a/talpid_ipc/src/ipc/mod.rs +++ b/talpid_ipc/src/ipc/mod.rs @@ -25,7 +25,7 @@ pub trait IpcServer { /// /// 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<()>; + fn start(self, on_message: Box<OnMessage<Self::MessageType>>) -> Result<()>; } error_chain!{ diff --git a/talpid_ipc/src/ipc/nop_ipc.rs b/talpid_ipc/src/ipc/nop_ipc.rs index 78860cab95..56e3eb8799 100644 --- a/talpid_ipc/src/ipc/nop_ipc.rs +++ b/talpid_ipc/src/ipc/nop_ipc.rs @@ -11,7 +11,7 @@ pub struct NopIpcServer; impl IpcServer for NopIpcServer { type MessageType = String; - fn start(self, _port: u16, _on_message: Box<OnMessage<Self::MessageType>>) -> Result<()> { + fn start(self, _on_message: Box<OnMessage<Self::MessageType>>) -> Result<()> { Err(ErrorKind::CouldNotStartServer.into()) } } diff --git a/talpid_ipc/src/ipc/zmq_ipc.rs b/talpid_ipc/src/ipc/zmq_ipc.rs index 0dcc8d96ae..733f42ca42 100644 --- a/talpid_ipc/src/ipc/zmq_ipc.rs +++ b/talpid_ipc/src/ipc/zmq_ipc.rs @@ -16,6 +16,7 @@ pub struct ZmqIpcServer<T> where T: 'static { parser: Box<MessageParser<T>>, + port: u16, } impl<T> IpcServer for ZmqIpcServer<T> @@ -23,8 +24,9 @@ impl<T> IpcServer for ZmqIpcServer<T> { type MessageType = T; - fn start(self, port: u16, on_message: Box<OnMessage<T>>) -> Result<()> { - let socket = Self::start_zmq_server(port).chain_err(|| ErrorKind::CouldNotStartServer)?; + fn start(self, on_message: Box<OnMessage<T>>) -> Result<()> { + let socket = + Self::start_zmq_server(self.port).chain_err(|| ErrorKind::CouldNotStartServer)?; let _ = Self::start_receive_loop(socket, on_message, self.parser); Ok(()) } @@ -76,12 +78,18 @@ mod tests { fn gives_error_when_unable_to_start() { let port = 1340; - let ipc_server1 = ZmqIpcServer { parser: Box::new(parse_to_test_enum) }; - let ipc_server2 = ZmqIpcServer { parser: Box::new(parse_to_test_enum) }; + let ipc_server1 = ZmqIpcServer { + port: port, + parser: Box::new(parse_to_test_enum), + }; + let ipc_server2 = ZmqIpcServer { + port: port, + parser: Box::new(parse_to_test_enum), + }; - ipc_server1.start(port, Box::new(|_| {})) + ipc_server1.start(Box::new(|_| {})) .expect("Unable to start the first server. Results inconclusive"); - let start_res = ipc_server2.start(port, Box::new(|_| {})); + let start_res = ipc_server2.start(Box::new(|_| {})); assert!(start_res.is_err()); let err = start_res.unwrap_err(); @@ -111,8 +119,11 @@ mod tests { fn connect_and_send(port: u16, message: u8) -> Receiver<Result<TestMessage>> { let (tx, rx) = mpsc::channel(); - let ipc_server = ZmqIpcServer { parser: Box::new(parse_to_test_enum) }; - ipc_server.start(port, Box::new(move |message| { let _ = tx.send(message); })) + let ipc_server = ZmqIpcServer { + port: port, + parser: Box::new(parse_to_test_enum), + }; + ipc_server.start(Box::new(move |message| { let _ = tx.send(message); })) .expect("Could not start the server"); let socket = connect_to_server(port).expect("Could not connect to the server"); |
