1 // Tags: not-a-test |
|
2 |
|
3 /* |
|
4 Copyright (C) 2005 Free Software Foundation |
|
5 |
|
6 This file is part of Mauve. |
|
7 |
|
8 Mauve is free software; you can redistribute it and/or modify |
|
9 it under the terms of the GNU General Public License as published by |
|
10 the Free Software Foundation; either version 2, or (at your option) |
|
11 any later version. |
|
12 |
|
13 Mauve is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Mauve; see the file COPYING. If not, write to |
|
20 the Free Software Foundation, 59 Temple Place - Suite 330, |
|
21 Boston, MA 02111-1307, USA. |
|
22 */ |
|
23 |
|
24 package gnu.testlet.java.net.Socket; |
|
25 import gnu.testlet.TestHarness; |
|
26 import java.net.*; |
|
27 import java.io.*; |
|
28 |
|
29 /* Implements a simple server socket listening on a port. |
|
30 Socket tests can connect to this port. */ |
|
31 |
|
32 class ServerThread extends Thread |
|
33 { |
|
34 ServerSocket sock; |
|
35 TestHarness harness; |
|
36 |
|
37 public ServerThread(TestHarness harness) |
|
38 { |
|
39 this(harness, 14610); |
|
40 } |
|
41 |
|
42 public ServerThread(TestHarness harness, int port) |
|
43 { |
|
44 this.harness = harness; |
|
45 try |
|
46 { |
|
47 sock = new ServerSocket(port); |
|
48 this.start(); |
|
49 } |
|
50 catch (IOException x) |
|
51 { |
|
52 harness.fail(x.toString()); |
|
53 } |
|
54 } |
|
55 |
|
56 public void close() |
|
57 { |
|
58 try |
|
59 { |
|
60 sock.close(); |
|
61 } |
|
62 catch (IOException x) |
|
63 { |
|
64 harness.fail(x.toString()); |
|
65 } |
|
66 } |
|
67 |
|
68 public void run() |
|
69 { |
|
70 try |
|
71 { |
|
72 while (true) |
|
73 { |
|
74 Socket s = sock.accept(); |
|
75 InputStream is = s.getInputStream(); |
|
76 byte[] data = new byte[512]; |
|
77 boolean done = false; |
|
78 while (!done) |
|
79 { |
|
80 if (is.read(data, 0, data.length) < 0) |
|
81 done = true; |
|
82 } |
|
83 } |
|
84 } |
|
85 catch (IOException x) |
|
86 { |
|
87 // Ignored |
|
88 } |
|
89 } |
|
90 } |
|