Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
dragonwell8_jdk
提交
52b2c472
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看板
提交
52b2c472
编写于
2月 25, 2014
作者:
K
kvn
浏览文件
操作
浏览文件
下载
差异文件
Merge
上级
1461f1b9
82ea0dd6
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
277 addition
and
158 deletion
+277
-158
src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
+11
-2
src/share/classes/sun/nio/ch/FileChannelImpl.java
src/share/classes/sun/nio/ch/FileChannelImpl.java
+1
-1
src/share/classes/sun/nio/ch/NativeThreadSet.java
src/share/classes/sun/nio/ch/NativeThreadSet.java
+11
-11
src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java
...classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java
+0
-1
src/solaris/native/sun/awt/gtk2_interface.c
src/solaris/native/sun/awt/gtk2_interface.c
+7
-0
src/solaris/native/sun/nio/ch/NativeThread.c
src/solaris/native/sun/nio/ch/NativeThread.c
+26
-19
test/ProblemList.txt
test/ProblemList.txt
+0
-5
test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java
...SetExtendedStateTest/ExceptionOnSetExtendedStateTest.java
+103
-0
test/java/nio/channels/Selector/ByteServer.java
test/java/nio/channels/Selector/ByteServer.java
+35
-33
test/java/nio/channels/Selector/ReadAfterConnect.java
test/java/nio/channels/Selector/ReadAfterConnect.java
+16
-18
test/java/nio/channels/Selector/SelectAfterRead.java
test/java/nio/channels/Selector/SelectAfterRead.java
+47
-45
test/java/nio/channels/Selector/SelectWrite.java
test/java/nio/channels/Selector/SelectWrite.java
+20
-23
未找到文件。
src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java
浏览文件 @
52b2c472
/*
* Copyright (c) 2011, 201
3
, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 201
4
, 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
...
...
@@ -583,7 +583,12 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// setVisible could have changed the native maximized state
deliverZoom
(
true
);
}
else
{
switch
(((
Frame
)
target
).
getExtendedState
())
{
int
frameState
=
((
Frame
)
target
).
getExtendedState
();
if
((
frameState
&
Frame
.
ICONIFIED
)
!=
0
)
{
// Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
frameState
=
Frame
.
ICONIFIED
;
}
switch
(
frameState
)
{
case
Frame
.
ICONIFIED
:
CWrapper
.
NSWindow
.
miniaturize
(
nsWindowPtr
);
break
;
...
...
@@ -788,6 +793,10 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
if
(
prevWindowState
==
windowState
)
return
;
final
long
nsWindowPtr
=
getNSWindowPtr
();
if
((
windowState
&
Frame
.
ICONIFIED
)
!=
0
)
{
// Treat all state bit masks with ICONIFIED bit as ICONIFIED state.
windowState
=
Frame
.
ICONIFIED
;
}
switch
(
windowState
)
{
case
Frame
.
ICONIFIED
:
if
(
prevWindowState
==
Frame
.
MAXIMIZED_BOTH
)
{
...
...
src/share/classes/sun/nio/ch/FileChannelImpl.java
浏览文件 @
52b2c472
...
...
@@ -110,7 +110,7 @@ public class FileChannelImpl
}
}
nd
.
preClose
(
fd
);
// signal any threads blocked on this channel
threads
.
signalAndWait
();
if
(
parent
!=
null
)
{
...
...
src/share/classes/sun/nio/ch/NativeThreadSet.java
浏览文件 @
52b2c472
...
...
@@ -82,8 +82,9 @@ class NativeThreadSet {
// Signals all threads in this set.
//
void
signalAndWait
()
{
synchronized
(
this
)
{
synchronized
void
signalAndWait
()
{
boolean
interrupted
=
false
;
while
(
used
>
0
)
{
int
u
=
used
;
int
n
=
elts
.
length
;
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
...
...
@@ -96,16 +97,15 @@ class NativeThreadSet {
break
;
}
waitingToEmpty
=
true
;
boolean
interrupted
=
false
;
while
(
used
>
0
)
{
try
{
wait
();
}
catch
(
InterruptedException
e
)
{
interrupted
=
true
;
}
try
{
wait
(
50
);
}
catch
(
InterruptedException
e
)
{
interrupted
=
true
;
}
finally
{
waitingToEmpty
=
false
;
}
if
(
interrupted
)
Thread
.
currentThread
().
interrupt
();
}
if
(
interrupted
)
Thread
.
currentThread
().
interrupt
();
}
}
src/share/classes/sun/nio/ch/SimpleAsynchronousFileChannelImpl.java
浏览文件 @
52b2c472
...
...
@@ -88,7 +88,6 @@ public class SimpleAsynchronousFileChannelImpl
invalidateAllLocks
();
// signal any threads blocked on this channel
nd
.
preClose
(
fdObj
);
threads
.
signalAndWait
();
// wait until all async I/O operations have completely gracefully
...
...
src/solaris/native/sun/awt/gtk2_interface.c
浏览文件 @
52b2c472
...
...
@@ -32,6 +32,7 @@
#include "java_awt_Transparency.h"
#include "jvm_md.h"
#include "sizecalc.h"
#include <jni_util.h>
#define GTK2_LIB_VERSIONED VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0")
#define GTK2_LIB JNI_LIB_NAME("gtk-x11-2.0")
...
...
@@ -456,13 +457,19 @@ void update_supported_actions(JNIEnv *env) {
const
gchar
*
const
*
schemes
=
NULL
;
jclass
cls_action
=
(
*
env
)
->
FindClass
(
env
,
"java/awt/Desktop$Action"
);
CHECK_NULL
(
cls_action
);
jclass
cls_xDesktopPeer
=
(
*
env
)
->
FindClass
(
env
,
"sun/awt/X11/XDesktopPeer"
);
CHECK_NULL
(
cls_xDesktopPeer
);
jfieldID
fld_supportedActions
=
(
*
env
)
->
GetStaticFieldID
(
env
,
cls_xDesktopPeer
,
"supportedActions"
,
"Ljava/util/List;"
);
CHECK_NULL
(
fld_supportedActions
);
jobject
supportedActions
=
(
*
env
)
->
GetStaticObjectField
(
env
,
cls_xDesktopPeer
,
fld_supportedActions
);
jclass
cls_arrayList
=
(
*
env
)
->
FindClass
(
env
,
"java/util/ArrayList"
);
CHECK_NULL
(
cls_arrayList
);
jmethodID
mid_arrayListAdd
=
(
*
env
)
->
GetMethodID
(
env
,
cls_arrayList
,
"add"
,
"(Ljava/lang/Object;)Z"
);
CHECK_NULL
(
mid_arrayListAdd
);
jmethodID
mid_arrayListClear
=
(
*
env
)
->
GetMethodID
(
env
,
cls_arrayList
,
"clear"
,
"()V"
);
CHECK_NULL
(
mid_arrayListClear
);
(
*
env
)
->
CallVoidMethod
(
env
,
supportedActions
,
mid_arrayListClear
);
...
...
src/solaris/native/sun/nio/ch/NativeThread.c
浏览文件 @
52b2c472
...
...
@@ -32,27 +32,32 @@
#include "sun_nio_ch_NativeThread.h"
#include "nio_util.h"
#ifdef __linux__
#include <pthread.h>
#include <sys/signal.h>
/* Also defined in src/solaris/native/java/net/linux_close.c */
#define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
#include <pthread.h>
#include <sys/signal.h>
/* Also defined in net/linux_close.c */
#define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
#elif __solaris__
#include <thread.h>
#include <signal.h>
#define INTERRUPT_SIGNAL (SIGRTMAX - 2)
#elif _ALLBSD_SOURCE
#include <pthread.h>
#include <signal.h>
/* Also defined in net/bsd_close.c */
#define INTERRUPT_SIGNAL SIGIO
#else
#error "missing platform-specific definition here"
#endif
static
void
nullHandler
(
int
sig
)
{
}
#endif
JNIEXPORT
void
JNICALL
Java_sun_nio_ch_NativeThread_init
(
JNIEnv
*
env
,
jclass
cl
)
{
#ifdef __linux__
/* Install the null handler for INTERRUPT_SIGNAL. This might overwrite the
* handler previously installed by java/net/linux_close.c, but that's okay
* since neither handler actually does anything. We install our own
...
...
@@ -67,25 +72,27 @@ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
sigemptyset
(
&
sa
.
sa_mask
);
if
(
sigaction
(
INTERRUPT_SIGNAL
,
&
sa
,
&
osa
)
<
0
)
JNU_ThrowIOExceptionWithLastError
(
env
,
"sigaction"
);
#endif
}
JNIEXPORT
jlong
JNICALL
Java_sun_nio_ch_NativeThread_current
(
JNIEnv
*
env
,
jclass
cl
)
{
#ifdef __
linux
__
return
(
long
)
pthread
_self
();
#ifdef __
solaris
__
return
(
jlong
)
thr
_self
();
#else
return
-
1
;
return
(
jlong
)
pthread_self
()
;
#endif
}
JNIEXPORT
void
JNICALL
Java_sun_nio_ch_NativeThread_signal
(
JNIEnv
*
env
,
jclass
cl
,
jlong
thread
)
{
#ifdef __linux__
if
(
pthread_kill
((
pthread_t
)
thread
,
INTERRUPT_SIGNAL
))
JNU_ThrowIOExceptionWithLastError
(
env
,
"Thread signal failed"
);
int
ret
;
#ifdef __solaris__
ret
=
thr_kill
((
thread_t
)
thread
,
INTERRUPT_SIGNAL
);
#else
ret
=
pthread_kill
((
pthread_t
)
thread
,
INTERRUPT_SIGNAL
);
#endif
if
(
ret
!=
0
)
JNU_ThrowIOExceptionWithLastError
(
env
,
"Thread signal failed"
);
}
test/ProblemList.txt
浏览文件 @
52b2c472
...
...
@@ -188,11 +188,6 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all
# 6963118
java/nio/channels/Selector/Wakeup.java windows-all
# 7133499, 7133497
java/nio/channels/AsyncCloseAndInterrupt.java macosx-all
java/nio/channels/AsynchronousFileChannel/Lock.java macosx-all
java/nio/channels/FileChannel/Transfer.java macosx-all
# 7141822
java/nio/channels/DatagramChannel/ChangingAddress.java macosx-all
...
...
test/java/awt/Frame/ExceptionOnSetExtendedStateTest/ExceptionOnSetExtendedStateTest.java
0 → 100644
浏览文件 @
52b2c472
/*
* Copyright (c) 2014, 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 8032078
@summary Frame.setExtendedState throws RuntimeException, if
windowState=ICONIFIED|MAXIMIZED_BOTH, on OS X
@author Anton Litvinov
*/
import
java.awt.*
;
import
sun.awt.SunToolkit
;
public
class
ExceptionOnSetExtendedStateTest
{
private
static
final
int
[]
frameStates
=
{
Frame
.
NORMAL
,
Frame
.
ICONIFIED
,
Frame
.
MAXIMIZED_BOTH
};
private
static
final
SunToolkit
toolkit
=
(
SunToolkit
)
Toolkit
.
getDefaultToolkit
();
private
static
boolean
validatePlatform
()
{
String
osName
=
System
.
getProperty
(
"os.name"
);
if
(
osName
==
null
)
{
throw
new
RuntimeException
(
"Name of the current OS could not be retrieved."
);
}
return
osName
.
startsWith
(
"Mac"
);
}
private
static
void
testStateChange
(
int
oldState
,
int
newState
,
boolean
decoratedFrame
)
{
System
.
out
.
println
(
String
.
format
(
"testStateChange: oldState='%d', newState='%d', decoratedFrame='%b'"
,
oldState
,
newState
,
decoratedFrame
));
Frame
frame
=
new
Frame
(
"ExceptionOnSetExtendedStateTest"
);
frame
.
setSize
(
200
,
200
);
frame
.
setUndecorated
(!
decoratedFrame
);
frame
.
setVisible
(
true
);
toolkit
.
realSync
();
frame
.
setExtendedState
(
oldState
);
sleep
(
1000
);
frame
.
setExtendedState
(
newState
);
boolean
stateWasNotChanged
=
true
;
int
currentState
=
0
;
for
(
int
i
=
0
;
(
i
<
3
)
&&
stateWasNotChanged
;
i
++)
{
sleep
(
1000
);
currentState
=
frame
.
getExtendedState
();
if
((
currentState
==
newState
)
||
(((
newState
&
Frame
.
ICONIFIED
)
!=
0
)
&&
((
currentState
&
Frame
.
ICONIFIED
)
!=
0
)))
{
stateWasNotChanged
=
false
;
}
}
frame
.
dispose
();
if
(
stateWasNotChanged
)
{
throw
new
RuntimeException
(
String
.
format
(
"Frame state was not changed. currentState='%d'"
,
currentState
));
}
}
private
static
void
sleep
(
int
millis
)
{
try
{
Thread
.
sleep
(
millis
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
)
{
if
(!
validatePlatform
())
{
System
.
out
.
println
(
"This test is only for OS X."
);
return
;
}
// Verify that changing states of decorated/undecorated frame to/from supported states
// and the state bit mask ICONIFIED | MAXIMIZED_BOTH does not raise RuntimeException.
for
(
int
i
=
0
;
i
<
frameStates
.
length
;
i
++)
{
testStateChange
(
frameStates
[
i
],
Frame
.
ICONIFIED
|
Frame
.
MAXIMIZED_BOTH
,
true
);
testStateChange
(
frameStates
[
i
],
Frame
.
ICONIFIED
|
Frame
.
MAXIMIZED_BOTH
,
false
);
testStateChange
(
Frame
.
ICONIFIED
|
Frame
.
MAXIMIZED_BOTH
,
frameStates
[
i
],
true
);
testStateChange
(
Frame
.
ICONIFIED
|
Frame
.
MAXIMIZED_BOTH
,
frameStates
[
i
],
false
);
}
}
}
test/java/nio/channels/Selector/ByteServer.java
浏览文件 @
52b2c472
...
...
@@ -22,52 +22,54 @@
*/
/**
*
* Utility class for tests. A simple server, which waits for a connection,
* writes out n bytes and waits.
* Utility class for tests. A simple "in-thread" server to accept connections
* and write bytes.
* @author kladko
*/
import
java.net.Socket
;
import
java.net.ServerSocket
;
import
java.net.SocketAddress
;
import
java.net.InetSocketAddress
;
import
java.io.IOException
;
import
java.io.Closeable
;
public
class
ByteServer
implements
Closeable
{
public
class
ByteServer
{
private
final
ServerSocket
ss
;
private
Socket
s
;
public
static
final
String
LOCALHOST
=
"localhost"
;
private
int
bytecount
;
private
Socket
socket
;
private
ServerSocket
serversocket
;
private
Thread
serverthread
;
volatile
Exception
savedException
;
ByteServer
()
throws
IOException
{
this
.
ss
=
new
ServerSocket
(
0
);
}
SocketAddress
address
()
{
return
new
InetSocketAddress
(
ss
.
getInetAddress
(),
ss
.
getLocalPort
());
}
public
ByteServer
(
int
bytecount
)
throws
Exception
{
this
.
bytecount
=
bytecount
;
serversocket
=
new
ServerSocket
(
0
);
void
acceptConnection
()
throws
IOException
{
if
(
s
!=
null
)
throw
new
IllegalStateException
(
"already connected"
);
this
.
s
=
ss
.
accept
();
}
public
int
port
()
{
return
serversocket
.
getLocalPort
();
void
closeConnection
()
throws
IOException
{
Socket
s
=
this
.
s
;
if
(
s
!=
null
)
{
this
.
s
=
null
;
s
.
close
();
}
}
public
void
start
()
{
serverthread
=
new
Thread
()
{
public
void
run
()
{
try
{
socket
=
serversocket
.
accept
();
socket
.
getOutputStream
().
write
(
new
byte
[
bytecount
]);
socket
.
getOutputStream
().
flush
();
}
catch
(
Exception
e
)
{
System
.
err
.
println
(
"Exception in ByteServer: "
+
e
);
System
.
exit
(
1
);
}
}
};
serverthread
.
start
();
void
write
(
int
count
)
throws
IOException
{
if
(
s
==
null
)
throw
new
IllegalStateException
(
"no connection"
);
s
.
getOutputStream
().
write
(
new
byte
[
count
]);
}
public
void
exit
()
throws
Exception
{
serverthread
.
join
();
socket
.
close
();
s
erversocket
.
close
();
public
void
close
()
throws
IO
Exception
{
if
(
s
!=
null
)
s
.
close
();
s
s
.
close
();
}
}
test/java/nio/channels/Selector/ReadAfterConnect.java
浏览文件 @
52b2c472
...
...
@@ -27,27 +27,25 @@
* @author kladko
*/
import
java.n
et.*
;
import
java.nio.
*
;
import
java.nio.channels.
*
;
import
java.n
io.channels.Selector
;
import
java.nio.
channels.SelectionKey
;
import
java.nio.channels.
SocketChannel
;
public
class
ReadAfterConnect
{
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
ByteServer
server
=
new
ByteServer
(
0
);
// server: accept connection and do nothing
server
.
start
();
InetSocketAddress
isa
=
new
InetSocketAddress
(
InetAddress
.
getByName
(
ByteServer
.
LOCALHOST
),
server
.
port
());
Selector
sel
=
Selector
.
open
();
SocketChannel
sc
=
SocketChannel
.
open
();
sc
.
connect
(
isa
);
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
// Previously channel would get selected here, although there is nothing to read
if
(
sel
.
selectNow
()
!=
0
)
throw
new
Exception
(
"Select returned nonzero value"
);
sc
.
close
();
server
.
exit
();
try
(
ByteServer
server
=
new
ByteServer
();
SocketChannel
sc
=
SocketChannel
.
open
(
server
.
address
()))
{
server
.
acceptConnection
();
try
(
Selector
sel
=
Selector
.
open
())
{
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
// Previously channel would get selected here, although there is nothing to read
if
(
sel
.
selectNow
()
!=
0
)
throw
new
Exception
(
"Select returned nonzero value"
);
}
}
}
}
test/java/nio/channels/Selector/SelectAfterRead.java
浏览文件 @
52b2c472
...
...
@@ -28,60 +28,62 @@
* @author kladko
*/
import
java.net.*
;
import
java.nio.*
;
import
java.nio.channels.*
;
import
java.nio.ByteBuffer
;
import
java.nio.channels.Selector
;
import
java.nio.channels.SelectionKey
;
import
java.nio.channels.SocketChannel
;
public
class
SelectAfterRead
{
final
static
int
TIMEOUT
=
1000
;
private
static
final
int
TIMEOUT
=
1000
;
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
InetAddress
lh
=
InetAddress
.
getByName
(
ByteServer
.
LOCALHOST
);
// server: accept connection and write one byte
ByteServer
server
=
new
ByteServer
(
1
);
server
.
start
();
Selector
sel
=
Selector
.
open
();
SocketChannel
sc
=
SocketChannel
.
open
();
sc
.
connect
(
new
InetSocketAddress
(
lh
,
server
.
port
()));
sc
.
read
(
ByteBuffer
.
allocate
(
1
));
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
// previously on Windows select would select channel here, although there was
// nothing to read
if
(
sel
.
selectNow
()
!=
0
)
throw
new
Exception
(
"Select returned nonzero value"
);
sc
.
close
();
sel
.
close
();
server
.
exit
();
try
(
ByteServer
server
=
new
ByteServer
();
SocketChannel
sc
=
SocketChannel
.
open
(
server
.
address
()))
{
server
.
acceptConnection
();
server
.
write
(
1
);
try
(
Selector
sel
=
Selector
.
open
())
{
sc
.
read
(
ByteBuffer
.
allocate
(
1
));
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
// previously on Windows select would select channel here, although there was
// nothing to read
if
(
sel
.
selectNow
()
!=
0
)
throw
new
Exception
(
"Select returned nonzero value"
);
}
}
// Now we will test a two reads combination
// server: accept connection and write two bytes
server
=
new
ByteServer
(
2
);
server
.
start
();
sc
=
SocketChannel
.
open
();
sc
.
connect
(
new
InetSocketAddress
(
lh
,
server
.
port
()));
sc
.
configureBlocking
(
false
);
sel
=
Selector
.
open
();
sc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
if
(
sel
.
select
(
TIMEOUT
)
!=
1
)
throw
new
Exception
(
"One selected key expected"
);
sel
.
selectedKeys
().
clear
();
// previously on Windows a channel would get selected only once
if
(
sel
.
selectNow
()
!=
1
)
throw
new
Exception
(
"One selected key expected"
);
// Previously on Windows two consequent reads would cause select()
// to select a channel, although there was nothing remaining to
// read in the channel
if
(
sc
.
read
(
ByteBuffer
.
allocate
(
1
))
!=
1
)
throw
new
Exception
(
"One byte expected"
);
if
(
sc
.
read
(
ByteBuffer
.
allocate
(
1
))
!=
1
)
throw
new
Exception
(
"One byte expected"
);
if
(
sel
.
selectNow
()
!=
0
)
throw
new
Exception
(
"Select returned nonzero value"
);
sc
.
close
();
sel
.
close
();
server
.
exit
();
try
(
ByteServer
server
=
new
ByteServer
();
SocketChannel
sc
=
SocketChannel
.
open
(
server
.
address
()))
{
server
.
acceptConnection
();
server
.
write
(
2
);
try
(
Selector
sel
=
Selector
.
open
())
{
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_READ
);
if
(
sel
.
select
(
TIMEOUT
)
!=
1
)
throw
new
Exception
(
"One selected key expected"
);
sel
.
selectedKeys
().
clear
();
// previously on Windows a channel would get selected only once
if
(
sel
.
selectNow
()
!=
1
)
throw
new
Exception
(
"One selected key expected"
);
// Previously on Windows two consequent reads would cause select()
// to select a channel, although there was nothing remaining to
// read in the channel
if
(
sc
.
read
(
ByteBuffer
.
allocate
(
1
))
!=
1
)
throw
new
Exception
(
"One byte expected"
);
if
(
sc
.
read
(
ByteBuffer
.
allocate
(
1
))
!=
1
)
throw
new
Exception
(
"One byte expected"
);
if
(
sel
.
selectNow
()
!=
0
)
throw
new
Exception
(
"Select returned nonzero value"
);
}
}
}
}
test/java/nio/channels/Selector/SelectWrite.java
浏览文件 @
52b2c472
...
...
@@ -22,36 +22,33 @@
*/
/* @test
@bug 4645302
@summary Socket with OP_WRITE would get selected only once
@author kladko
*
@bug 4645302
*
@summary Socket with OP_WRITE would get selected only once
*
@author kladko
*/
import
java.net.*
;
import
java.nio.*
;
import
java.nio.channels.*
;
import
java.nio.channels.Selector
;
import
java.nio.channels.SelectionKey
;
import
java.nio.channels.SocketChannel
;
public
class
SelectWrite
{
public
static
void
main
(
String
[]
argv
)
throws
Exception
{
ByteServer
server
=
new
ByteServer
(
0
);
// server: accept connection and do nothing
server
.
start
();
InetSocketAddress
isa
=
new
InetSocketAddress
(
InetAddress
.
getByName
(
ByteServer
.
LOCALHOST
),
server
.
port
());
Selector
sel
=
Selector
.
open
();
SocketChannel
sc
=
SocketChannel
.
open
(
);
sc
.
connect
(
isa
);
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_WRITE
);
sel
.
select
();
sel
.
selectedKeys
().
clear
(
);
if
(
sel
.
select
()
==
0
)
{
throw
new
Exception
(
"Select returned zero"
);
try
(
ByteServer
server
=
new
ByteServer
(
);
SocketChannel
sc
=
SocketChannel
.
open
(
server
.
address
()))
{
server
.
acceptConnection
();
try
(
Selector
sel
=
Selector
.
open
())
{
sc
.
configureBlocking
(
false
);
sc
.
register
(
sel
,
SelectionKey
.
OP_WRITE
);
sel
.
select
(
);
sel
.
selectedKeys
().
clear
(
);
if
(
sel
.
select
()
==
0
)
{
throw
new
Exception
(
"Select returned zero"
);
}
}
}
sc
.
close
();
sel
.
close
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录