2 * Test interruptable I/O.
4 * Note that this test will not run under Sun's JDK1.2 on Solaris, see
5 * http://developer.java.sun.com/developer/bugParade/bugs/4178050.html
7 * It's unlikely to work on Windows either, see
8 * http://developer.java.sun.com/developer/bugParade/bugs/4154947.html
10 * It it supported by Kaffe's jthreads, though it may not work under other
11 * threading systems either. XXX
13 * @author Godmar Back <gback@cs.utah.edu>
18 public class SoInterrupt {
19 public static void main(String av[]) throws Exception {
20 final boolean verbose = av.length > 0;
21 final String foo = "foo";
22 final Thread main = Thread.currentThread();
28 server = new ServerSocket(tryport);
30 } catch (IOException _) {}
32 final int port = tryport;
33 Thread watchdog = new Thread() {
36 Thread.sleep(10 * 1000);
37 } catch (InterruptedException _) { }
38 System.out.println("Watchdog Failure: Time out.");
44 Thread t = new Thread() {
47 // let main thread wait a while
50 } catch (InterruptedException e) {
51 System.out.println("Failure " + e);
54 System.out.println("interrupting " + main);
57 // give it some more time
60 } catch (InterruptedException e) {
61 System.out.println("Failure " + e);
66 System.out.println("connecting...");
67 Socket s = new Socket(InetAddress.getByName(null), port);
71 } catch (InterruptedException e) {
72 System.out.println("Failure " + e);
76 System.out.println("interrupting again " + main);
82 } catch (InterruptedException e) {
83 System.out.println("Failure " + e);
87 PrintWriter p = new PrintWriter(s.getOutputStream());
90 } catch (Exception e) {
91 System.out.println("Failure " + e);
96 Socket rsocket = null;
99 System.out.println("waiting for client...");
100 rsocket = server.accept();
102 System.out.println("accepted..." + rsocket);
103 } catch (InterruptedIOException e) {
105 System.out.println(e);
106 System.out.println("Success 1.");
109 System.out.println("waiting for client again...");
110 rsocket = server.accept();
111 System.out.println("Success 2.");
112 InputStream is = rsocket.getInputStream();
113 LineNumberReader r = new LineNumberReader(new InputStreamReader(is));
117 } catch (InterruptedIOException e) {
118 // System.out.println(e);
119 System.out.println("Success 3.");
121 String s = r.readLine();
123 System.out.println("Success 4.");
125 System.out.println("Failure: `" + s + "'");