OLD | NEW |
1 #!/usr/bin/env dart | 1 #!/usr/bin/env dart |
2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 2 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
3 // for details. All rights reserved. Use of this source code is governed by a | 3 // for details. All rights reserved. Use of this source code is governed by a |
4 // BSD-style license that can be found in the LICENSE file. | 4 // BSD-style license that can be found in the LICENSE file. |
5 | 5 |
6 #library("total:runner"); | 6 #library("total:runner"); |
7 | 7 |
8 typedef void ExitCallback(int status, String exitString); | 8 typedef void ExitCallback(int status, String exitString); |
9 | 9 |
10 void main() { | 10 void main() { |
11 String SERVER_EXEC_PATH = './TotalServer.dart'; | 11 String SERVER_EXEC_PATH = './TotalServer.dart'; |
12 String RESTART = "GRACEFUL RESTART!!"; | 12 String RESTART = "GRACEFUL RESTART!!"; |
13 String EXIT = "GRACEFUL EXIT!!"; | 13 String EXIT = "GRACEFUL EXIT!!"; |
14 | 14 |
15 void keepServerRunning(int status, ServerRunner runner) { | 15 void keepServerRunning(int status, ServerRunner runner) { |
16 switch (runner.lastExitString) { | 16 switch (runner.lastExitString) { |
17 case RESTART: | 17 case RESTART: |
| 18 runner.lastExitString = ''; |
18 runner.run(keepServerRunning); | 19 runner.run(keepServerRunning); |
19 break; | 20 break; |
20 case EXIT: | 21 case EXIT: |
21 break; | 22 break; |
22 default: | 23 default: |
23 print("ERROR: exiting due to unknown condition. Exit status: $status." | 24 print("ERROR: exiting due to unknown condition. Exit status: $status." |
24 + " Exit string: '${runner.lastExitString}'"); | 25 + " Exit string: '${runner.lastExitString}'"); |
25 break; | 26 break; |
26 } | 27 } |
27 } | 28 } |
(...skipping 20 matching lines...) Expand all Loading... |
48 void run(ExitCallback exitCallback) { | 49 void run(ExitCallback exitCallback) { |
49 Process dart = new Process(DART_EXEC_PATH, [_serverMain]); | 50 Process dart = new Process(DART_EXEC_PATH, [_serverMain]); |
50 | 51 |
51 dart.setExitHandler((int status) { | 52 dart.setExitHandler((int status) { |
52 dart.close(); | 53 dart.close(); |
53 exitCallback(status, this); | 54 exitCallback(status, this); |
54 }); | 55 }); |
55 | 56 |
56 dart.start(); | 57 dart.start(); |
57 | 58 |
58 readMore(false, dart.stdoutStream, new List<int>(_BUFSIZE), new StringBuffer
()); | 59 readMore(false, dart.stdout, new List<int>(_BUFSIZE), new StringBuffer()); |
59 readMore(false, dart.stderrStream, new List<int>(_BUFSIZE), new StringBuffer
()); | 60 readMore(false, dart.stderr, new List<int>(_BUFSIZE), new StringBuffer()); |
60 } | 61 } |
61 | 62 |
62 void readMore(bool fromCallback, InputStream i, List<int> buf, StringBuffer re
adSoFar) { | 63 void readMore(bool fromCallback, InputStream i, List<int> buf, StringBuffer re
adSoFar) { |
63 if (fromCallback) { | 64 if (fromCallback) { |
64 processBuffer(buf, readSoFar); | 65 processBuffer(buf, readSoFar); |
65 } | 66 } |
66 while(i.read(buf, 0, buf.length, () => readMore(true, i, buf, readSoFar))) { | 67 while(i.read(buf, 0, buf.length, () => readMore(true, i, buf, readSoFar))) { |
67 processBuffer(buf, readSoFar); | 68 processBuffer(buf, readSoFar); |
68 } | 69 } |
69 } | 70 } |
(...skipping 18 matching lines...) Expand all Loading... |
88 if (line.contains(e, 0)) { | 89 if (line.contains(e, 0)) { |
89 lastExitString = e; | 90 lastExitString = e; |
90 return true; | 91 return true; |
91 } else { | 92 } else { |
92 return false; | 93 return false; |
93 } | 94 } |
94 }); | 95 }); |
95 } | 96 } |
96 | 97 |
97 } | 98 } |
OLD | NEW |