提交 971794ac authored 作者: Thomas Mueller's avatar Thomas Mueller

When trying to connect to a server using TCP/IP failed, it will retry at most…

When trying to connect to a server using TCP/IP failed, it will retry at most until the timeout. Before, it was the timeout multiplied with the retry count.
上级 7f313623
...@@ -100,6 +100,7 @@ public class NetUtils { ...@@ -100,6 +100,7 @@ public class NetUtils {
* @return the socket * @return the socket
*/ */
public static Socket createSocket(InetAddress address, int port, boolean ssl) throws IOException { public static Socket createSocket(InetAddress address, int port, boolean ssl) throws IOException {
long start = System.currentTimeMillis();
for (int i = 0;; i++) { for (int i = 0;; i++) {
try { try {
if (ssl) { if (ssl) {
...@@ -110,6 +111,11 @@ public class NetUtils { ...@@ -110,6 +111,11 @@ public class NetUtils {
SysProperties.SOCKET_CONNECT_TIMEOUT); SysProperties.SOCKET_CONNECT_TIMEOUT);
return socket; return socket;
} catch (IOException e) { } catch (IOException e) {
if (System.currentTimeMillis() - start >= SysProperties.SOCKET_CONNECT_TIMEOUT) {
// either it was a connect timeout,
// or list of different exceptions
throw e;
}
if (i >= SysProperties.SOCKET_CONNECT_RETRY) { if (i >= SysProperties.SOCKET_CONNECT_RETRY) {
throw e; throw e;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论