Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
879f7042
D
dragonwell8_jdk
项目概览
openanolis
/
dragonwell8_jdk
通知
4
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
dragonwell8_jdk
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
879f7042
编写于
7月 30, 2010
作者:
M
michaelm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6510892: com/sun/net/httpserver/bugs/B6361557.java fails
Reviewed-by: chegar
上级
71f4d04a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
48 addition
and
20 deletion
+48
-20
test/com/sun/net/httpserver/bugs/B6361557.java
test/com/sun/net/httpserver/bugs/B6361557.java
+48
-20
未找到文件。
test/com/sun/net/httpserver/bugs/B6361557.java
浏览文件 @
879f7042
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
/**
/**
* @test
* @test
* @bug 6361557
* @bug 6361557
* @run main/othervm B6361557
* @summary Lightweight HTTP server quickly runs out of file descriptors on Linux
* @summary Lightweight HTTP server quickly runs out of file descriptors on Linux
*/
*/
...
@@ -63,6 +64,9 @@ public class B6361557 {
...
@@ -63,6 +64,9 @@ public class B6361557 {
}
}
}
}
final
static
String
request
=
"GET /test/foo.html HTTP/1.1\r\nContent-length: 0\r\n\r\n"
;
final
static
ByteBuffer
requestBuf
=
ByteBuffer
.
allocate
(
64
).
put
(
request
.
getBytes
());
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Handler
handler
=
new
Handler
();
Handler
handler
=
new
Handler
();
InetSocketAddress
addr
=
new
InetSocketAddress
(
0
);
InetSocketAddress
addr
=
new
InetSocketAddress
(
0
);
...
@@ -73,48 +77,72 @@ public class B6361557 {
...
@@ -73,48 +77,72 @@ public class B6361557 {
server
.
setExecutor
(
executor
);
server
.
setExecutor
(
executor
);
server
.
start
();
server
.
start
();
ByteBuffer
buf
=
ByteBuffer
.
allocate
(
4096
);
InetSocketAddress
destaddr
=
new
InetSocketAddress
(
InetSocketAddress
destaddr
=
new
InetSocketAddress
(
"127.0.0.1"
,
server
.
getAddress
().
getPort
()
"127.0.0.1"
,
server
.
getAddress
().
getPort
()
);
);
System
.
out
.
println
(
"destaddr "
+
destaddr
);
System
.
out
.
println
(
"destaddr "
+
destaddr
);
Selector
selector
=
Selector
.
open
();
Selector
selector
=
Selector
.
open
();
int
i
=
0
;
int
requests
=
0
;
int
responses
=
0
;
while
(
true
)
{
while
(
true
)
{
i
++;
int
selres
=
selector
.
select
(
1
);
int
selres
=
selector
.
select
(
1
);
Set
<
SelectionKey
>
selkeys
=
selector
.
selectedKeys
();
Set
<
SelectionKey
>
selkeys
=
selector
.
selectedKeys
();
for
(
SelectionKey
key
:
selkeys
)
{
for
(
SelectionKey
key
:
selkeys
)
{
if
(
key
.
isReadable
())
{
if
(
key
.
isReadable
())
{
SocketChannel
chan
=
(
SocketChannel
)
key
.
channel
();
SocketChannel
chan
=
(
SocketChannel
)
key
.
channel
();
buf
.
clear
();
ByteBuffer
buf
=
(
ByteBuffer
)
key
.
attachment
();
try
{
try
{
int
x
=
chan
.
read
(
buf
);
int
x
=
chan
.
read
(
buf
);
if
(
x
==
-
1
)
{
if
(
x
==
-
1
||
responseComplete
(
buf
))
{
key
.
attach
(
null
);
chan
.
close
();
chan
.
close
();
responses
++;
}
}
}
catch
(
IOException
e
)
{}
}
catch
(
IOException
e
)
{}
}
}
}
}
if
(
i
<
NUM
)
{
if
(
requests
<
NUM
)
{
SocketChannel
schan
=
SocketChannel
.
open
(
destaddr
);
SocketChannel
schan
=
SocketChannel
.
open
(
destaddr
);
String
cmd
=
"GET /test/foo.html HTTP/1.1\r\nContent-length: 0\r\n\r\n"
;
requestBuf
.
rewind
();
buf
.
rewind
();
buf
.
put
(
cmd
.
getBytes
());
buf
.
flip
();
int
c
=
0
;
int
c
=
0
;
while
(
b
uf
.
remaining
()
>
0
)
{
while
(
requestB
uf
.
remaining
()
>
0
)
{
c
+=
schan
.
write
(
b
uf
);
c
+=
schan
.
write
(
requestB
uf
);
}
}
schan
.
configureBlocking
(
false
);
schan
.
configureBlocking
(
false
);
schan
.
register
(
selector
,
SelectionKey
.
OP_READ
,
null
);
schan
.
register
(
selector
,
SelectionKey
.
OP_READ
,
ByteBuffer
.
allocate
(
100
));
}
else
{
requests
++;
}
if
(
responses
==
NUM
)
{
System
.
out
.
println
(
"Finished clients"
);
System
.
out
.
println
(
"Finished clients"
);
server
.
stop
(
1
);
break
;
executor
.
shutdown
();
}
return
;
}
server
.
stop
(
1
);
selector
.
close
();
executor
.
shutdown
();
}
/* Look for CR LF CR LF */
static
boolean
responseComplete
(
ByteBuffer
buf
)
{
int
pos
=
buf
.
position
();
buf
.
flip
();
byte
[]
lookingFor
=
new
byte
[]
{
'\r'
,
'\n'
,
'\r'
,
'\n'
};
int
lookingForCount
=
0
;
while
(
buf
.
hasRemaining
())
{
byte
b
=
buf
.
get
();
if
(
b
==
lookingFor
[
lookingForCount
])
{
lookingForCount
++;
if
(
lookingForCount
==
4
)
{
return
true
;
}
}
else
{
lookingForCount
=
0
;
}
}
}
}
buf
.
position
(
pos
);
buf
.
limit
(
buf
.
capacity
());
return
false
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录