/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 6285901 6501089
* @summary Check no data is written to wrong socket channel during async closing.
* @author Xueming Shen
*/
public class AsyncCloseChannel {
static volatile boolean failed = false;
static volatile boolean keepGoing = true;
static int sensorPort;
static int targetPort;
return;
}
}
keepGoing = false;
try {
} catch (Exception e) {}
if (failed)
throw new RuntimeException("AsyncCloseChannel2 failed after <"
+ acceptCount + "> times of accept!");
}
while(keepGoing) {
try {
new Thread() {
public void run() {
try {
int c = s.getInputStream().read();
if(c != -1) {
// No data is ever written to the peer's socket!
+ (char) c);
failed = true;
}
} catch (IOException ex) {
} finally {
closeIt(s);
}
}
}.start();
} catch (IOException ex) {
}
}
}
}
while (keepGoing) {
try {
acceptCount++;
new Thread() {
public void run() {
boolean empty = true;
try {
for(;;) {
int c = s.getInputStream().read();
if(c == -1) {
if(!empty)
break;
}
empty = false;
}
} catch (IOException ex) {
} finally {
closeIt(s);
}
}
}.start();
} catch (IOException ex) {
}
}
}
}
private static boolean wake;
public void run() {
while (keepGoing) {
try {
s = new Socket();
synchronized(this) {
try {
wait();
} catch (InterruptedException ex) { }
}
wake = false;
}
try {
} catch (InterruptedException ex) { }
} catch (IOException ex) {
} finally {
if(s != null) {
try {
s.close();
}
}
}
}
public SensorClient() {
theClient = this;
}
public static void wakeMe() {
synchronized(theClient) {
wake = true;
}
}
}
volatile boolean ready = false;
public void run() {
while(keepGoing) {
try {
s.finishConnect();
ready = false;
public void run() {
try {
for(;;) {
b.clear();
b.put((byte) 'A');
b.flip();
s.write(b);
ready = true;
}
} catch (IOException ex) {
if(!(ex instanceof ClosedChannelException))
}
}
};
t.start();
try {
} catch (InterruptedException ex) {}
}
s.close();
t.join();
} catch (IOException ex) {
+ ex.getMessage());
} catch (InterruptedException ex) {}
}
}
}
public ServerThread() {
super();
try {
} catch (IOException ex) {
}
}
public void interrupt() {
super.interrupt();
try {
} catch (IOException ex) {
}
}
}
public void run() {
try {
runEx();
}
}
}
try {
if(s != null)
s.close();
} catch (IOException ex) { }
}
}