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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 void init() { | 120 void init() { |
121 // Setup request handlers. | 121 // Setup request handlers. |
122 _requestHandlers = new Map(); | 122 _requestHandlers = new Map(); |
123 _requestHandlers["/echo"] = _echoHandler; | 123 _requestHandlers["/echo"] = _echoHandler; |
124 } | 124 } |
125 | 125 |
126 void dispatch(message, SendPort replyTo) { | 126 void dispatch(message, SendPort replyTo) { |
127 if (message.isStart) { | 127 if (message.isStart) { |
128 try { | 128 try { |
129 HttpServer.bind().then((server) { | 129 HttpServer.bind("127.0.0.1", 0).then((server) { |
130 _server = server; | 130 _server = server; |
131 _server.listen(_requestReceivedHandler); | 131 _server.listen(_requestReceivedHandler); |
132 replyTo.send( | 132 replyTo.send( |
133 new IsolatedHttpServerStatus.started(_server.port), null); | 133 new IsolatedHttpServerStatus.started(_server.port), null); |
134 }); | 134 }); |
135 } catch (e) { | 135 } catch (e) { |
136 replyTo.send(new IsolatedHttpServerStatus.error(), null); | 136 replyTo.send(new IsolatedHttpServerStatus.error(), null); |
137 } | 137 } |
138 } else if (message.isStop) { | 138 } else if (message.isStop) { |
139 _server.close(); | 139 _server.close(); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 if (chunkedEncoding) { | 203 if (chunkedEncoding) { |
204 server.chunkedEncoding(); | 204 server.chunkedEncoding(); |
205 } | 205 } |
206 server.start(); | 206 server.start(); |
207 } | 207 } |
208 | 208 |
209 void main() { | 209 void main() { |
210 testRead(true); | 210 testRead(true); |
211 testRead(false); | 211 testRead(false); |
212 } | 212 } |
OLD | NEW |