diff options
author | Igor Matuszewski <Xanewok@gmail.com> | 2020-03-13 23:23:54 +0100 |
---|---|---|
committer | Igor Matuszewski <igor@sequoia-pgp.org> | 2020-03-18 17:52:34 +0100 |
commit | 6c9ea4e1543d54100cbf74f0d9a970bcb93494dc (patch) | |
tree | 59ba22c28f339b53a3d3ff48a9f1a32982bbcecc | |
parent | 034e79ab839b17476110fb72f0a5f9c70a9b612f (diff) |
ipc: Ask the OS for a random port in TcpListener::bind
-rw-r--r-- | ipc/src/lib.rs | 14 |
1 files changed, 1 insertions, 13 deletions
diff --git a/ipc/src/lib.rs b/ipc/src/lib.rs index c4946816..364a58b0 100644 --- a/ipc/src/lib.rs +++ b/ipc/src/lib.rs @@ -231,22 +231,10 @@ impl Descriptor { } } - /// Try to create a TCP socket, bind it to a random port on - /// localhost. - fn listen(&self) -> Result<TcpListener> { - let port = OsRng.next_u32() as u16; - Ok(TcpListener::bind((LOCALHOST, port))?) - } - /// Start the service, either as an external process or as a /// thread. fn start(&self, external: bool) -> Result<SocketAddr> { - /* Listen on a random port on localhost. */ - let mut listener = self.listen(); - while listener.is_err() { - listener = self.listen(); - } - let listener = listener.unwrap(); + let listener = TcpListener::bind((LOCALHOST, 0)).unwrap(); let addr = listener.local_addr()?; /* Start the server, connect to it, and send the cookie. */ |