OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of vmservice_io; | 5 part of vmservice_io; |
6 | 6 |
7 class WebSocketClient extends Client { | 7 class WebSocketClient extends Client { |
8 static const int PARSE_ERROR_CODE = 4000; | 8 static const int PARSE_ERROR_CODE = 4000; |
9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; | 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; |
10 static const int NOT_MAP_ERROR_CODE = 4002; | 10 static const int NOT_MAP_ERROR_CODE = 4002; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 // HTTP based service request. | 150 // HTTP based service request. |
151 try { | 151 try { |
152 var client = new HttpRequestClient(request, _service); | 152 var client = new HttpRequestClient(request, _service); |
153 var message = new Message.fromUri(client, request.uri); | 153 var message = new Message.fromUri(client, request.uri); |
154 client.onMessage(null, message); | 154 client.onMessage(null, message); |
155 } catch (e) { | 155 } catch (e) { |
156 print('Unexpected error processing HTTP request uri: ' | 156 print('Unexpected error processing HTTP request uri: ' |
157 '${request.uri}\n$e\n'); | 157 '${request.uri}\n$e\n'); |
158 rethrow; | 158 rethrow; |
159 } | 159 } |
160 | |
161 } | 160 } |
162 | 161 |
163 Future startup() { | 162 Future startup() { |
164 if (_server != null) { | 163 if (_server != null) { |
165 // Already running. | 164 // Already running. |
166 return new Future.value(this); | 165 return new Future.value(this); |
167 } | 166 } |
168 | 167 |
| 168 var address = new InternetAddress(_ip); |
169 // Startup HTTP server. | 169 // Startup HTTP server. |
170 return HttpServer.bind(_ip, _port).then((s) { | 170 return HttpServer.bind(address, _port).then((s) { |
171 _server = s; | 171 _server = s; |
172 _server.listen(_requestHandler); | 172 _server.listen(_requestHandler, cancelOnError: true); |
173 var ip = _server.address.address.toString(); | 173 var ip = _server.address.address.toString(); |
| 174 var port = _server.port.toString(); |
174 if (_displayMessages) { | 175 if (_displayMessages) { |
175 var port = _server.port.toString(); | |
176 print('Observatory listening on http://$ip:$port'); | 176 print('Observatory listening on http://$ip:$port'); |
177 } | 177 } |
178 // Server is up and running. | 178 // Server is up and running. |
179 _notifyServerState(ip, _server.port); | 179 _notifyServerState(ip, _server.port); |
| 180 onServerAddressChange('http://$ip:$port'); |
180 return this; | 181 return this; |
181 }).catchError((e, st) { | 182 }).catchError((e, st) { |
182 print('Could not start Observatory HTTP server:\n$e\n$st\n'); | 183 print('Could not start Observatory HTTP server:\n$e\n$st\n'); |
183 _notifyServerState("", 0); | 184 _notifyServerState("", 0); |
| 185 onServerAddressChange(null); |
184 return this; | 186 return this; |
185 }); | 187 }); |
186 } | 188 } |
187 | 189 |
188 close(bool force) { | 190 Future cleanup(bool force) { |
189 if (_server == null) { | 191 if (_server == null) { |
190 return new Future.value(null); | 192 return new Future.value(null); |
191 } | 193 } |
192 return _server.close(force: force); | 194 return _server.close(force: force); |
193 } | 195 } |
194 | 196 |
195 Future shutdown(bool forced) { | 197 Future shutdown(bool forced) { |
196 if (_server == null) { | 198 if (_server == null) { |
197 // Not started. | 199 // Not started. |
198 return new Future.value(this); | 200 return new Future.value(this); |
199 } | 201 } |
200 | 202 |
201 // Force displaying of status messages if we are forcibly shutdown. | 203 // Force displaying of status messages if we are forcibly shutdown. |
202 _displayMessages = _displayMessages || forced; | 204 _displayMessages = _displayMessages || forced; |
203 | 205 |
204 // Shutdown HTTP server and subscription. | 206 // Shutdown HTTP server and subscription. |
205 var ip = _server.address.address.toString(); | 207 var ip = _server.address.address.toString(); |
206 var port = _server.port.toString(); | 208 var port = _server.port.toString(); |
207 return close(forced).then((_) { | 209 return cleanup(forced).then((_) { |
208 if (_displayMessages) { | 210 if (_displayMessages) { |
209 print('Observatory no longer listening on http://$ip:$port'); | 211 print('Observatory no longer listening on http://$ip:$port'); |
210 } | 212 } |
211 _server = null; | 213 _server = null; |
212 _notifyServerState("", 0); | 214 _notifyServerState("", 0); |
| 215 onServerAddressChange(null); |
213 return this; | 216 return this; |
214 }).catchError((e, st) { | 217 }).catchError((e, st) { |
215 _server = null; | 218 _server = null; |
216 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); | 219 print('Could not shutdown Observatory HTTP server:\n$e\n$st\n'); |
217 _notifyServerState("", 0); | 220 _notifyServerState("", 0); |
| 221 onServerAddressChange(null); |
218 return this; | 222 return this; |
219 }); | 223 }); |
220 } | 224 } |
221 | 225 |
222 } | 226 } |
223 | 227 |
224 void _notifyServerState(String ip, int port) | 228 void _notifyServerState(String ip, int port) |
225 native "VMServiceIO_NotifyServerState"; | 229 native "VMServiceIO_NotifyServerState"; |
OLD | NEW |