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 // VMOptions= | 5 // VMOptions= |
6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
9 | 9 |
10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 SendPort get dispatchSendPort => _dispatchPort.sendPort; | 131 SendPort get dispatchSendPort => _dispatchPort.sendPort; |
132 | 132 |
133 void dispatch(message) { | 133 void dispatch(message) { |
134 IsolatedHttpServerCommand command = message[0]; | 134 IsolatedHttpServerCommand command = message[0]; |
135 SendPort replyTo = message[1]; | 135 SendPort replyTo = message[1]; |
136 if (command.isStart) { | 136 if (command.isStart) { |
137 try { | 137 try { |
138 HttpServer.bind("127.0.0.1", 0).then((server) { | 138 HttpServer.bind("127.0.0.1", 0).then((server) { |
139 _server = server; | 139 _server = server; |
140 _server.listen(_requestReceivedHandler); | 140 _server.listen(_requestReceivedHandler); |
141 replyTo.send( | 141 replyTo.send(new IsolatedHttpServerStatus.started(_server.port)); |
142 new IsolatedHttpServerStatus.started(_server.port), null); | |
143 }); | 142 }); |
144 } catch (e) { | 143 } catch (e) { |
145 replyTo.send(new IsolatedHttpServerStatus.error(), null); | 144 replyTo.send(new IsolatedHttpServerStatus.error()); |
146 } | 145 } |
147 } else if (command.isStop) { | 146 } else if (command.isStop) { |
148 _server.close(); | 147 _server.close(); |
149 _dispatchPort.close(); | 148 _dispatchPort.close(); |
150 replyTo.send(new IsolatedHttpServerStatus.stopped(), null); | 149 replyTo.send(new IsolatedHttpServerStatus.stopped()); |
151 } else if (command.isChunkedEncoding) { | 150 } else if (command.isChunkedEncoding) { |
152 _chunkedEncoding = true; | 151 _chunkedEncoding = true; |
153 } | 152 } |
154 } | 153 } |
155 | 154 |
156 void _requestReceivedHandler(HttpRequest request) { | 155 void _requestReceivedHandler(HttpRequest request) { |
157 var requestHandler =_requestHandlers[request.uri.path]; | 156 var requestHandler =_requestHandlers[request.uri.path]; |
158 if (requestHandler != null) { | 157 if (requestHandler != null) { |
159 requestHandler(request); | 158 requestHandler(request); |
160 } else { | 159 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } | 209 } |
211 | 210 |
212 server.setServerStartedHandler(runTest); | 211 server.setServerStartedHandler(runTest); |
213 server.start(chunkedEncoding); | 212 server.start(chunkedEncoding); |
214 } | 213 } |
215 | 214 |
216 void main() { | 215 void main() { |
217 testRead(true); | 216 testRead(true); |
218 testRead(false); | 217 testRead(false); |
219 } | 218 } |
OLD | NEW |