Skip to content

Commit

Permalink
Merge pull request #411 from JeppeOvervad/socketnetwork_timeout_and_p…
Browse files Browse the repository at this point in the history
…olling

Socketnetwork timeout and polling
  • Loading branch information
quackzar committed Sep 28, 2023
2 parents d925d15 + 0050fe6 commit 660ffce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -137,7 +137,7 @@ private Map<Integer, Socket> connectClient(final NetworkConfiguration conf)
} catch (ConnectException e) {
// A ConnectionException is expected if the opposing side is not listening for our
// connection attempt yet. We ignore this and try again.
Thread.sleep(1L << ++attempts);
Thread.sleep(Math.min(1 << attempts++, 5_000));
// This should probably not busy-wait for each party
}
}
Expand Down
Expand Up @@ -102,7 +102,17 @@ public SocketNetwork(NetworkConfiguration conf, Map<Integer, Socket> socketMap)
* @param conf the configuration to load the network from.
*/
public SocketNetwork(NetworkConfiguration conf) {
this(conf, new Connector(conf, Duration.of(1, ChronoUnit.MINUTES)).getSocketMap());
this(conf, Duration.of(1, ChronoUnit.MINUTES));
}

/**
* Construct a socket network with a specific timeout.
*
* @param conf the configuration to load the network from.
* @param timeout duration to wait until timeout when connecting the network.
*/
public SocketNetwork(NetworkConfiguration conf, Duration timeout) {
this(conf, new Connector(conf, timeout).getSocketMap());
}

/**
Expand Down

0 comments on commit 660ffce

Please sign in to comment.