Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
0807c38b
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看板
提交
0807c38b
编写于
6月 09, 2010
作者:
A
alanb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
6935563: (dc) Improve connection reset/port unreachable handling [win]
Reviewed-by: chegar
上级
82b4353a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
123 addition
and
1 deletion
+123
-1
src/windows/native/sun/nio/ch/DatagramChannelImpl.c
src/windows/native/sun/nio/ch/DatagramChannelImpl.c
+6
-0
src/windows/native/sun/nio/ch/Net.c
src/windows/native/sun/nio/ch/Net.c
+23
-1
test/java/nio/channels/DatagramChannel/SelectWhenRefused.java
.../java/nio/channels/DatagramChannel/SelectWhenRefused.java
+94
-0
未找到文件。
src/windows/native/sun/nio/ch/DatagramChannelImpl.c
浏览文件 @
0807c38b
...
...
@@ -120,6 +120,12 @@ Java_sun_nio_ch_DatagramChannelImpl_disconnect0(JNIEnv *env, jobject this,
rv
=
connect
((
SOCKET
)
fd
,
(
struct
sockaddr
*
)
&
sa
,
sa_len
);
if
(
rv
==
SOCKET_ERROR
)
{
handleSocketError
(
env
,
WSAGetLastError
());
}
else
{
/* Disable WSAECONNRESET errors as socket is no longer connected */
BOOL
enable
=
FALSE
;
DWORD
bytesReturned
=
0
;
WSAIoctl
((
SOCKET
)
fd
,
SIO_UDP_CONNRESET
,
&
enable
,
sizeof
(
enable
),
NULL
,
0
,
&
bytesReturned
,
NULL
,
NULL
);
}
}
...
...
src/windows/native/sun/nio/ch/Net.c
浏览文件 @
0807c38b
...
...
@@ -67,6 +67,14 @@ typedef struct my_group_source_req {
#define COPY_INET6_ADDRESS(env, source, target) \
(*env)->GetByteArrayRegion(env, source, 0, 16, target)
/**
* Enable or disable receipt of WSAECONNRESET errors.
*/
static
void
setConnectionReset
(
SOCKET
s
,
BOOL
enable
)
{
DWORD
bytesReturned
=
0
;
WSAIoctl
(
s
,
SIO_UDP_CONNRESET
,
&
enable
,
sizeof
(
enable
),
NULL
,
0
,
&
bytesReturned
,
NULL
,
NULL
);
}
JNIEXPORT
void
JNICALL
...
...
@@ -109,6 +117,12 @@ Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
setsockopt
(
s
,
IPPROTO_IPV6
,
IPV6_V6ONLY
,
(
const
char
*
)
&
opt
,
sizeof
(
opt
));
}
/* Disable WSAECONNRESET errors for initially unconnected UDP sockets */
if
(
!
stream
)
{
setConnectionReset
(
s
,
FALSE
);
}
}
else
{
NET_ThrowNew
(
env
,
WSAGetLastError
(),
"socket"
);
}
...
...
@@ -149,12 +163,13 @@ Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6, job
SOCKETADDRESS
sa
;
int
rv
;
int
sa_len
;
SOCKET
s
=
(
SOCKET
)
fdval
(
env
,
fdo
);
if
(
NET_InetAddressToSockaddr
(
env
,
iao
,
port
,
(
struct
sockaddr
*
)
&
sa
,
&
sa_len
,
preferIPv6
)
!=
0
)
{
return
IOS_THROWN
;
}
rv
=
connect
(
fdval
(
env
,
fdo
)
,
(
struct
sockaddr
*
)
&
sa
,
sa_len
);
rv
=
connect
(
s
,
(
struct
sockaddr
*
)
&
sa
,
sa_len
);
if
(
rv
!=
0
)
{
int
err
=
WSAGetLastError
();
if
(
err
==
WSAEINPROGRESS
||
err
==
WSAEWOULDBLOCK
)
{
...
...
@@ -162,6 +177,13 @@ Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6, job
}
NET_ThrowNew
(
env
,
err
,
"connect"
);
return
IOS_THROWN
;
}
else
{
/* Enable WSAECONNRESET errors when a UDP socket is connected */
int
type
=
0
,
optlen
=
sizeof
(
type
);
rv
=
getsockopt
(
s
,
SOL_SOCKET
,
SO_TYPE
,
(
char
*
)
&
type
,
&
optlen
);
if
(
rv
==
0
&&
type
==
SOCK_DGRAM
)
{
setConnectionReset
(
s
,
TRUE
);
}
}
return
1
;
}
...
...
test/java/nio/channels/DatagramChannel/SelectWhenRefused.java
0 → 100644
浏览文件 @
0807c38b
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
* @bug 6935563
* @summary Test that Selector does not select an unconnected DatagramChannel when
* ICMP port unreachable received
*/
import
java.nio.ByteBuffer
;
import
java.nio.channels.*
;
import
java.net.*
;
import
java.io.IOException
;
public
class
SelectWhenRefused
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
DatagramChannel
dc
=
DatagramChannel
.
open
().
bind
(
new
InetSocketAddress
(
0
));
int
port
=
dc
.
socket
().
getLocalPort
();
dc
.
close
();
// datagram sent to this address should be refused
SocketAddress
refuser
=
new
InetSocketAddress
(
InetAddress
.
getLocalHost
(),
port
);
dc
=
DatagramChannel
.
open
().
bind
(
new
InetSocketAddress
(
0
));
try
{
dc
.
configureBlocking
(
false
);
Selector
sel
=
Selector
.
open
();
dc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
/* Test 1: not connected so ICMP port unreachable should not be received */
sendDatagram
(
dc
,
refuser
);
int
n
=
sel
.
select
(
2000
);
if
(
n
>
0
)
{
throw
new
RuntimeException
(
"Unexpected wakeup"
);
}
/* Test 2: connected so ICMP port unreachable may be received */
dc
.
connect
(
refuser
);
try
{
sendDatagram
(
dc
,
refuser
);
n
=
sel
.
select
(
2000
);
if
(
n
>
0
)
{
sel
.
selectedKeys
().
clear
();
try
{
n
=
dc
.
read
(
ByteBuffer
.
allocate
(
100
));
throw
new
RuntimeException
(
"Unexpected datagram received"
);
}
catch
(
PortUnreachableException
pue
)
{
// expected
}
}
}
finally
{
dc
.
disconnect
();
}
/* Test 3: not connected so ICMP port unreachable should not be received */
sendDatagram
(
dc
,
refuser
);
n
=
sel
.
select
(
2000
);
if
(
n
>
0
)
{
throw
new
RuntimeException
(
"Unexpected wakeup after disconnect"
);
}
}
finally
{
dc
.
close
();
}
}
static
void
sendDatagram
(
DatagramChannel
dc
,
SocketAddress
remote
)
throws
IOException
{
ByteBuffer
bb
=
ByteBuffer
.
wrap
(
"Greetings!"
.
getBytes
());
dc
.
send
(
bb
,
remote
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录