make Runtime._syscall() protected so it can be overridden from outside the package
[nestedvm.git] / src / tests / Echo.java
1 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
2 // Licensed under the Apache License 2.0 ("the License").
3 // You may not use this file except in compliance with the License.
4
5 package tests;
6
7 import java.net.*;
8
9 import org.ibex.nestedvm.Runtime;
10
11 public class Echo {
12     private static final int PORT = 2000;
13     public static void main(String[] args) throws Exception {
14         ServerSocket sock = new ServerSocket(PORT);
15         System.err.println("Listening on " + PORT);
16         for(;;) new Client(sock.accept()).go();
17     }
18     
19     private static class Client implements Runnable {
20         private Socket sock;
21         public Client(Socket sock) { this.sock = sock; }
22         public void go() { new Thread(this).start(); }
23         public void run() {
24             try {
25                 Runtime task = (Runtime) Class.forName("tests.EchoHelper").newInstance();
26                 task.closeFD(0);
27                 task.closeFD(1);
28                 //task.closeFD(2);
29                 task.addFD(new Runtime.InputOutputStreamFD(sock.getInputStream()));
30                 task.addFD(new Runtime.InputOutputStreamFD(sock.getOutputStream()));
31                 //task.dupFD(1);
32                 
33                 int status = task.run(new String[]{"EchoHelper"} );
34                 System.err.println("Exit status: " + status);
35             } catch(Exception e) {
36                 System.err.println(e);
37             }
38         }
39     }
40 }