| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #library("total:server"); | 5 #library("total:server"); |
| 6 | 6 |
| 7 #import("../../chat/chat_server_lib.dart"); | 7 #import("../../chat/chat_server_lib.dart"); |
| 8 #import("../../chat/http.dart"); | 8 #import("../../chat/http.dart"); |
| 9 #import("Dartc.dart"); | 9 #import("Dartc.dart"); |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 addHandler("/adm/Adminz.js", | 49 addHandler("/adm/Adminz.js", |
| 50 (HTTPRequest request, HTTPResponse response) | 50 (HTTPRequest request, HTTPResponse response) |
| 51 => fileHandler(request, response, "${CLIENT_DIR}/Adminz.js")); | 51 => fileHandler(request, response, "${CLIENT_DIR}/Adminz.js")); |
| 52 addHandler("/adm/stop", stopServer); | 52 addHandler("/adm/stop", stopServer); |
| 53 addHandler("/adm/restart", restartServer); | 53 addHandler("/adm/restart", restartServer); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void restartServer(HTTPRequest request, HTTPResponse response) { | 56 void restartServer(HTTPRequest request, HTTPResponse response) { |
| 57 writeData(request, response, 'Restarting, KBBS', 'text/plain'); | 57 writeData(request, response, 'Restarting, KBBS', 'text/plain'); |
| 58 stop(); | 58 stop(); |
| 59 print("GRACEFUL RESTART!! TODO: make server exit gracefully"); | 59 print("GRACEFUL RESTART!!"); |
| 60 throw "GRACEFUL RESTART!! TODO: make server exit gracefully"; | 60 exit(42); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void stopServer(HTTPRequest request, HTTPResponse response) { | 63 void stopServer(HTTPRequest request, HTTPResponse response) { |
| 64 writeData(request, response, 'Exiting, KTHXBYE', 'text/plain'); | 64 writeData(request, response, 'Exiting, KTHXBYE', 'text/plain'); |
| 65 stop(); | 65 stop(); |
| 66 print("GRACEFUL EXIT!! TODO: make server exit gracefully"); | 66 print("GRACEFUL EXIT!!"); |
| 67 throw "GRACEFUL EXIT!! TODO: make server exit gracefully"; | 67 exit(0); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void writeData(HTTPRequest request, HTTPResponse response, String message, Str
ing mimeType) { | 70 void writeData(HTTPRequest request, HTTPResponse response, String message, Str
ing mimeType) { |
| 71 response.setHeader("Content-Type", mimeType); | 71 response.setHeader("Content-Type", mimeType); |
| 72 | 72 |
| 73 List<int> buffer = message.charCodes(); | 73 List<int> buffer = message.charCodes(); |
| 74 response.writeList(buffer, 0, buffer.length, null); | 74 response.writeList(buffer, 0, buffer.length, null); |
| 75 response.writeDone(); | 75 response.writeDone(); |
| 76 } | 76 } |
| 77 | 77 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 104 errorDiv.appendChild(errorSpan); | 104 errorDiv.appendChild(errorSpan); |
| 105 | 105 |
| 106 document.body.appendChild(errorDiv); | 106 document.body.appendChild(errorDiv); |
| 107 '''; | 107 '''; |
| 108 writeData(request, response, errorScript, "application/javascript"); | 108 writeData(request, response, errorScript, "application/javascript"); |
| 109 } | 109 } |
| 110 }); | 110 }); |
| 111 } | 111 } |
| 112 } | 112 } |
| 113 | 113 |
| OLD | NEW |