Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a1f890af
提交
a1f890af
authored
2月 06, 2010
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A workaround for a Windows socket problem has been implemented.
上级
43c91a62
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
64 行增加
和
56 行删除
+64
-56
changelog.html
h2/src/docsrc/html/changelog.html
+2
-1
SysProperties.java
h2/src/main/org/h2/constant/SysProperties.java
+8
-0
NetUtils.java
h2/src/main/org/h2/util/NetUtils.java
+12
-4
TestNetUtils.java
h2/src/test/org/h2/test/unit/TestNetUtils.java
+42
-51
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
a1f890af
...
...
@@ -18,7 +18,8 @@ Change Log
<h1>
Change Log
</h1>
<h2>
Next Version (unreleased)
</h2>
<ul><li>
The Recover tool did not convert correctly convert CLOB data with non-ASCII characters.
<ul><li>
A workaround for a Windows socket problem has been implemented. Thanks a lot to Sergi Vladykin.
</li><li>
The Recover tool did not convert correctly convert CLOB data with non-ASCII characters.
</li><li>
Tools: the method run(String... args) has been renamed to runTool(String... args)
so it can't be confused with run().
</li><li>
Server.startWebServer(Connection) was not working as expected.
...
...
h2/src/main/org/h2/constant/SysProperties.java
浏览文件 @
a1f890af
...
...
@@ -496,6 +496,14 @@ public class SysProperties {
*/
public
static
final
boolean
SHARE_LINKED_CONNECTIONS
=
getBooleanSetting
(
"h2.shareLinkedConnections"
,
true
);
/**
* System property <code>h2.socketConnectRetry</code> (default: 16).<br />
* The number of times to retry opening a socket. Windows sometimes fails
* to open a socket, see bug
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213296
*/
public
static
final
int
SOCKET_CONNECT_RETRY
=
getIntSetting
(
"h2.socketConnectRetry"
,
16
);
/**
* System property <code>h2.socketConnectTimeout</code> (default: 2000).<br />
* The timeout in milliseconds to connect to a server.
...
...
h2/src/main/org/h2/util/NetUtils.java
浏览文件 @
a1f890af
...
...
@@ -102,7 +102,7 @@ public class NetUtils {
* @return the socket
*/
public
static
Socket
createSocket
(
InetAddress
address
,
int
port
,
boolean
ssl
)
throws
IOException
{
for
(
;;
)
{
for
(
int
i
=
0
;;
i
++
)
{
try
{
if
(
ssl
)
{
return
SecureSocketFactory
.
createSocket
(
address
,
port
);
...
...
@@ -112,9 +112,17 @@ public class NetUtils {
SysProperties
.
SOCKET_CONNECT_TIMEOUT
);
return
socket
;
}
catch
(
BindException
e
)
{
// Workaround for Windows problem with frequent connections:
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213296
// trying to connect again
if
(
i
>=
SysProperties
.
SOCKET_CONNECT_RETRY
)
{
throw
e
;
}
// wait a bit and retry
try
{
// sleep at most 256 ms
long
sleep
=
Math
.
min
(
256
,
i
*
i
);
Thread
.
sleep
(
sleep
);
}
catch
(
InterruptedException
e2
)
{
// ignore
}
}
}
}
...
...
h2/src/test/org/h2/test/unit/TestNetUtils.java
浏览文件 @
a1f890af
/**
*
/*
* Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License,
* Version 1.0, and under the Eclipse Public License, Version 1.0
* (http://h2database.com/html/license.html).
* Initial Developer: Sergi Vladykin
*/
package
org
.
h2
.
test
.
unit
;
...
...
@@ -9,126 +12,114 @@ import java.net.Socket;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.h2.engine.Constants
;
import
org.h2.test.TestBase
;
import
org.h2.util.NetUtils
;
/**
* Test the network utilities.
*
* @author Sergi Vladykin
*/
public
class
TestNetUtils
extends
TestBase
{
private
static
final
int
PORT
=
9111
;
/**
* @param args
* Run just this test.
*
* @param a ignored
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
...
a
)
throws
Exception
{
TestBase
.
createCaller
().
init
().
test
();
}
@Override
public
void
test
()
throws
Exception
{
testFrequentConnections
(
false
);
testFrequentConnections
(
true
);
testFrequentConnections
(
false
,
1000
);
testFrequentConnections
(
true
,
100
);
testFrequentConnections
(
false
,
1000
);
testFrequentConnections
(
true
,
100
);
}
private
void
testFrequentConnections
(
boolean
ssl
)
throws
Exception
{
final
ServerSocket
serverSock
=
NetUtils
.
createServerSocket
(
Constants
.
DEFAULT_TCP_PORT
,
ssl
);
private
void
testFrequentConnections
(
boolean
ssl
,
int
count
)
throws
Exception
{
final
ServerSocket
serverSocket
=
NetUtils
.
createServerSocket
(
PORT
,
ssl
);
final
AtomicInteger
counter
=
new
AtomicInteger
(
count
);
Thread
serverThread
=
new
Thread
()
{
@Override
public
void
run
()
{
while
(!
isInterrupted
())
{
try
{
Socket
socket
=
serverSock
.
accept
();
Socket
socket
=
serverSocket
.
accept
();
System
.
out
.
println
(
"opened "
+
counter
);
socket
.
close
();
}
catch
(
Exception
e
)
{
// ignore
}
}
System
.
out
.
println
(
"stopped "
);
}
};
serverThread
.
start
();
// System.out.println("Server started.");
AtomicInteger
counter
=
new
AtomicInteger
();
try
{
Set
<
ConnectWorker
>
workers
=
new
HashSet
<
ConnectWorker
>();
for
(
int
i
=
0
;
i
<
1
0
;
i
++)
{
workers
.
add
(
new
ConnectWorker
(
ssl
,
workers
,
counter
));
for
(
int
i
=
0
;
i
<
1
;
i
++)
{
workers
.
add
(
new
ConnectWorker
(
ssl
,
counter
));
}
// ensure the server is started
Thread
.
sleep
(
100
);
for
(
ConnectWorker
worker
:
workers
)
{
worker
.
start
();
}
// System.out.println("Workers started.");
Exception
exception
=
null
;
for
(
ConnectWorker
worker
:
workers
)
{
worker
.
join
();
if
(
exception
==
null
)
{
exception
=
worker
.
getException
();
// if (exception != null) {
// System.out.println("Exception set.");
// }
}
Exception
e
=
worker
.
getException
();
if
(
e
!=
null
)
{
e
.
printStackTrace
();
}
// System.out.println("All joined.");
if
(
exception
!=
null
)
{
throw
exception
;
}
}
finally
{
serverThread
.
interrupt
();
try
{
serverSock
.
close
();
serverSock
et
.
close
();
}
catch
(
Exception
e
)
{
// ignore
}
// System.out.println("Server stopped.");
serverThread
.
interrupt
();
serverThread
.
join
();
}
}
/**
*
*
A worker thread to test connecting.
*/
private
class
ConnectWorker
extends
Thread
{
private
static
final
int
MAX_CONNECT_COUNT
=
10000
;
private
final
boolean
ssl
;
private
final
Set
<
ConnectWorker
>
workers
;
private
final
AtomicInteger
counter
;
private
Exception
exception
;
private
volatile
Exception
exception
;
public
ConnectWorker
(
boolean
ssl
,
Set
<
ConnectWorker
>
workers
,
AtomicInteger
counter
)
{
public
ConnectWorker
(
boolean
ssl
,
AtomicInteger
counter
)
{
this
.
ssl
=
ssl
;
this
.
workers
=
workers
;
this
.
counter
=
counter
;
}
@Override
public
void
run
()
{
try
{
while
(!
isInterrupted
()
&&
counter
.
incrementAndGet
()
<
MAX_CONNECT_COUNT
)
{
Socket
sock
=
NetUtils
.
createSocket
(
"127.0.0.1"
,
Constants
.
DEFAULT_TCP_PORT
,
ssl
);
// System.out.println(COUNTER.get());
while
(!
isInterrupted
()
&&
counter
.
decrementAndGet
()
>
0
)
{
Socket
socket
=
NetUtils
.
createLoopbackSocket
(
PORT
,
ssl
);
try
{
sock
.
close
();
sock
et
.
close
();
}
catch
(
IOException
e
)
{
// ignore
}
}
}
catch
(
Exception
e
)
{
this
.
exception
=
e
;
for
(
ConnectWorker
worker
:
workers
)
{
worker
.
interrupt
();
}
exception
=
new
Exception
(
"count: "
+
counter
,
e
);
}
}
/**
* @return the exception
*/
public
Exception
getException
()
{
return
exception
;
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论