| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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('frog_server'); | 5 #library('frog_server'); |
| 6 | 6 |
| 7 #import('dart:io'); | 7 #import('dart:io'); |
| 8 #import('../../lib/json/json.dart'); | 8 #import('../../lib/json/json.dart'); |
| 9 #import('../lang.dart'); | 9 #import('../lang.dart'); |
| 10 #import('../file_system_vm.dart'); | 10 #import('../file_system_vm.dart'); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 socket.close(); | 124 socket.close(); |
| 125 break; | 125 break; |
| 126 default: | 126 default: |
| 127 print('info: unknown command "${request["command"]}"'); | 127 print('info: unknown command "${request["command"]}"'); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 /// Accepts an incoming socket connection | 131 /// Accepts an incoming socket connection |
| 132 onConnect(Socket socket) { | 132 onConnect(Socket socket) { |
| 133 var bytes = new List<int>(); | 133 var bytes = new List<int>(); |
| 134 socket.dataHandler = () { | 134 socket.onData = () { |
| 135 var pos = bytes.length; | 135 var pos = bytes.length; |
| 136 var len = socket.available(); | 136 var len = socket.available(); |
| 137 bytes.insertRange(pos, len); | 137 bytes.insertRange(pos, len); |
| 138 socket.readList(bytes, pos, len); | 138 socket.readList(bytes, pos, len); |
| 139 handleRequest(bytes, socket); | 139 handleRequest(bytes, socket); |
| 140 }; | 140 }; |
| 141 socket.errorHandler = () => socket.close(); | 141 socket.onError = () => socket.close(); |
| 142 socket.closeHandler = () => socket.close(); | 142 socket.onClosed = () => socket.close(); |
| 143 | 143 |
| 144 // Close the serverSocket - we only ever service one client. | 144 // Close the serverSocket - we only ever service one client. |
| 145 serverSocket.close(); | 145 serverSocket.close(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 /// This token is used by the editor to know when frogc has successfully come up
. | 148 /// This token is used by the editor to know when frogc has successfully come up
. |
| 149 final STARTUP_TOKEN = 'frog: accepting connections'; | 149 final STARTUP_TOKEN = 'frog: accepting connections'; |
| 150 | 150 |
| 151 /// Initialize the server and start listening for requests. Needs hostname/ip | 151 /// Initialize the server and start listening for requests. Needs hostname/ip |
| 152 /// and port that it should listen on, and the Frog library directory. | 152 /// and port that it should listen on, and the Frog library directory. |
| 153 ServerSocket startServer(String homedir, String host, int port) { | 153 ServerSocket startServer(String homedir, String host, int port) { |
| 154 // Initialize the compiler. Only need to happen once. | 154 // Initialize the compiler. Only need to happen once. |
| 155 initializeCompiler(homedir); | 155 initializeCompiler(homedir); |
| 156 serverSocket = new ServerSocket(host, port, 50); | 156 serverSocket = new ServerSocket(host, port, 50); |
| 157 serverSocket.connectionHandler = onConnect; | 157 serverSocket.onConnection = onConnect; |
| 158 print('$STARTUP_TOKEN on $host:${serverSocket.port}'); | 158 print('$STARTUP_TOKEN on $host:${serverSocket.port}'); |
| 159 return serverSocket; | 159 return serverSocket; |
| 160 } | 160 } |
| 161 | 161 |
| 162 /// Main entry point for FrogServer. | 162 /// Main entry point for FrogServer. |
| 163 main() { | 163 main() { |
| 164 // TODO(jmesserly): until we have a way of getting the executable's path, | 164 // TODO(jmesserly): until we have a way of getting the executable's path, |
| 165 // we'll run from current working directory. | 165 // we'll run from current working directory. |
| 166 var homedir = new File('.').fullPathSync(); | 166 var homedir = new File('.').fullPathSync(); |
| 167 | 167 |
| 168 var argv = new Options().arguments; | 168 var argv = new Options().arguments; |
| 169 var host = argv.length > 0 ? argv[0] : '127.0.0.1'; | 169 var host = argv.length > 0 ? argv[0] : '127.0.0.1'; |
| 170 var port = argv.length > 1 ? Math.parseInt(argv[1]) : 1236; | 170 var port = argv.length > 1 ? Math.parseInt(argv[1]) : 1236; |
| 171 startServer(homedir, host, port); | 171 startServer(homedir, host, port); |
| 172 } | 172 } |
| OLD | NEW |