summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-03-22 14:32:12 +0800
committerErik Larkö <erik@mullvad.net>2017-03-22 14:33:23 +0800
commitd5a8d70e7cef9cc757480ac41a2ab88e085b92df (patch)
tree42b8603e867d91bf64ee4e29aa7766a8b3a08ed7
parente3870e91df3558ab7ae3c853009632b42de32e63 (diff)
downloadmullvadvpn-d5a8d70e7cef9cc757480ac41a2ab88e085b92df.tar.xz
mullvadvpn-d5a8d70e7cef9cc757480ac41a2ab88e085b92df.zip
Attempt to start the HTTP server on different ports
-rw-r--r--talpid_ipc/src/http_ipc.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/talpid_ipc/src/http_ipc.rs b/talpid_ipc/src/http_ipc.rs
index bfa21756f5..dc554d8bfa 100644
--- a/talpid_ipc/src/http_ipc.rs
+++ b/talpid_ipc/src/http_ipc.rs
@@ -11,15 +11,21 @@ pub fn start_new_server<T, U, F>(on_message: F) -> Result<IpcServerId>
U: serde::Serialize,
F: FnMut(Result<T>) -> U + Send + 'static
{
- let addr = "127.0.0.1:5000";
+ for port in 5000..5010 {
+ let addr = format!("127.0.0.1:{}", port);
- tiny_http::Server::http(addr)
- .map_err(|e| chain_boxed_err(e, ErrorKind::CouldNotStartServer))
- .and_then(|server| {
- start_receive_loop(server, on_message);
+ if let Ok(server) = start_http_server(&addr) {
+ let _ = start_receive_loop(server, on_message);
debug!("Started a HTTP IPC server on {}", addr);
- Ok(format!("http://{}", addr))
- })
+ return Ok(format!("http://{}", addr));
+ }
+ }
+
+ bail!(ErrorKind::CouldNotStartServer)
+}
+
+fn start_http_server(addr: &str) -> Result<tiny_http::Server> {
+ tiny_http::Server::http(addr).map_err(|e| chain_boxed_err(e, ErrorKind::CouldNotStartServer))
}
fn chain_boxed_err(boxed_cause: Box<::std::error::Error>, new_error: ErrorKind) -> super::Error {