jdk/test/java/nio/channels/SocketChannel/AsyncCloseChannel.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 702 3bd5e70b2fe9
child 5506 202f599c92aa
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
715
f16baef3a20e 6719955: Update copyright year
xdono
parents: 702
diff changeset
     2
 * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/* @test
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    25
 * @bug 6285901 6501089
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Check no data is written to wrong socket channel during async closing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @author Xueming Shen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.nio.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.nio.channels.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
public class AsyncCloseChannel {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    36
    static volatile boolean failed = false;
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    37
    static volatile boolean keepGoing = true;
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    38
    static int maxAcceptCount = 100;
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    39
    static volatile int acceptCount = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    static String host = "127.0.0.1";
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    41
    static int sensorPort;
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    42
    static int targetPort;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        if (System.getProperty("os.name").startsWith("Windows")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
            System.err.println("WARNING: Still does not work on Windows!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        Thread ss = new SensorServer(); ss.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        Thread ts = new TargetServer(); ts.start();
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    51
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    52
        sensorPort = ((ServerThread)ss).server.getLocalPort();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    53
        targetPort = ((ServerThread)ts).server.getLocalPort();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    54
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        Thread sc = new SensorClient(); sc.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        Thread tc = new TargetClient(); tc.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        while(acceptCount < maxAcceptCount && !failed) {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    59
            Thread.sleep(10);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        keepGoing = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            ss.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            ts.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            sc.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            tc.interrupt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        } catch (Exception e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (failed)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            throw new RuntimeException("AsyncCloseChannel2 failed after <"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                       + acceptCount + "> times of accept!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    73
    static class SensorServer extends ServerThread {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public void runEx() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            while(keepGoing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    final Socket s = server.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                    new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                int c = s.getInputStream().read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                if(c != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                    // No data is ever written to the peer's socket!
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    84
                                    System.err.println("Oops: read a character: "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                                                       + (char) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                                    failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                closeIt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                } catch (IOException ex) {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
    96
                    System.err.println("Exception on sensor server " + ex.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   102
    static class TargetServer extends ServerThread {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        public void runEx() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            while (keepGoing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    final Socket s = server.accept();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    acceptCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                            boolean empty = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                for(;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                    int c = s.getInputStream().read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                    if(c == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                        if(!empty)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                    empty = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                                closeIt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    }.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                } catch (IOException ex) {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   128
                    System.err.println("Exception on target server " + ex.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    static class SensorClient extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        private static boolean wake;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        private static SensorClient theClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            while (keepGoing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                Socket s = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    s = new Socket();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    synchronized(this) {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   143
                        while(!wake && keepGoing) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                wait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                            } catch (InterruptedException ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                        }
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   148
                        wake = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    s.connect(new InetSocketAddress(host, sensorPort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                        Thread.sleep(10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    } catch (InterruptedException ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                } catch (IOException ex) {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   155
                    System.err.println("Exception on sensor client " + ex.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    if(s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                            s.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        } catch(IOException ex) { ex.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        public SensorClient() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            theClient = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        public static void wakeMe() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            synchronized(theClient) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                wake = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                theClient.notify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    static class TargetClient extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        volatile boolean ready = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            while(keepGoing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    final SocketChannel s = SocketChannel.open(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        new InetSocketAddress(host, targetPort));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    s.finishConnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    s.socket().setSoLinger(false, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    ready = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    Thread t = new Thread() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                            ByteBuffer b = ByteBuffer.allocate(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                for(;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                    b.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                    b.put((byte) 'A');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                    b.flip();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                    s.write(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                                    ready = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                if(!(ex instanceof ClosedChannelException))
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   201
                                    System.err.println("Exception in target client child "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                                                       + ex.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                    t.start();
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   207
                    while(!ready && keepGoing) {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   208
                        try {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   209
                            Thread.sleep(10);
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   210
                        } catch (InterruptedException ex) {}
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   211
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                    s.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    SensorClient.wakeMe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    t.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                } catch (IOException ex) {
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   216
                     System.err.println("Exception in target client parent "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                        + ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                } catch (InterruptedException ex) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
702
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   223
    static abstract class ServerThread extends Thread {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   224
        ServerSocket server;
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   225
        public ServerThread() {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   226
            super();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   227
            try {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   228
                server = new ServerSocket(0);
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   229
            } catch (IOException ex) {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   230
                ex.printStackTrace();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   231
            }
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   232
        }
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   233
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   234
        public void interrupt() {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   235
            super.interrupt();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   236
            if (server != null) {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   237
                try {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   238
                    server.close();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   239
                } catch (IOException ex) {
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   240
                    ex.printStackTrace();
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   241
                }
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   242
            }
3bd5e70b2fe9 6501089: test/java/nio/channels/SocketChannel/AsyncCloseChannel.java failing (timeout) on Linux
sherman
parents: 2
diff changeset
   243
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                runEx();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        abstract void runEx() throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public static void closeIt(Socket s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            if(s != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                s.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        } catch (IOException ex) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
}