Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: tests/standalone/io/http_advanced_test.dart

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/standalone/io/echo_server_stream_test.dart ('k') | tests/standalone/io/http_basic_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/http_advanced_test.dart
diff --git a/tests/standalone/io/http_advanced_test.dart b/tests/standalone/io/http_advanced_test.dart
index deab970f648843671eb3b2b1b415805bd1bef7f0..63a3be8128f9dde071ee9e382bf1525ff3a28937 100644
--- a/tests/standalone/io/http_advanced_test.dart
+++ b/tests/standalone/io/http_advanced_test.dart
@@ -15,39 +15,43 @@ import 'dart:isolate';
class IsolatedHttpServer {
IsolatedHttpServer()
: _statusPort = new ReceivePort(),
- _serverPort = null {
- _serverPort = spawnFunction(startIsolatedHttpServer);
- }
+ _serverPort = null;
void setServerStartedHandler(void startedCallback(int port)) {
_startedCallback = startedCallback;
}
void start() {
+ ReceivePort receivePort = new ReceivePort();
+ var remote = Isolate.spawn(startIsolatedHttpServer, receivePort.sendPort);
+ receivePort.first.then((port) {
+ _serverPort = port;
+
+ // Send server start message to the server.
+ var command = new IsolatedHttpServerCommand.start();
+ port.send([command, _statusPort.sendPort]);
+ });
+
// Handle status messages from the server.
- _statusPort.receive((var status, SendPort replyTo) {
+ _statusPort.listen((var status) {
if (status.isStarted) {
_startedCallback(status.port);
}
});
-
- // Send server start message to the server.
- var command = new IsolatedHttpServerCommand.start();
- _serverPort.send(command, _statusPort.toSendPort());
}
void shutdown() {
// Send server stop message to the server.
- _serverPort.send(new IsolatedHttpServerCommand.stop(),
- _statusPort.toSendPort());
+ _serverPort.send([new IsolatedHttpServerCommand.stop(),
+ _statusPort.sendPort]);
_statusPort.close();
}
void chunkedEncoding() {
// Send chunked encoding message to the server.
- _serverPort.send(
+ _serverPort.send([
new IsolatedHttpServerCommand.chunkedEncoding(),
- _statusPort.toSendPort());
+ _statusPort.sendPort]);
}
ReceivePort _statusPort; // Port for receiving messages from the server.
@@ -93,10 +97,10 @@ class IsolatedHttpServerStatus {
}
-void startIsolatedHttpServer() {
+void startIsolatedHttpServer(SendPort replyTo) {
var server = new TestServer();
server.init();
- port.receive(server.dispatch);
+ replyTo.send(server.dispatchSendPort);
}
@@ -201,10 +205,16 @@ class TestServer {
_requestHandlers["/contenttype2"] = _contentType2Handler;
_requestHandlers["/cookie1"] = _cookie1Handler;
_requestHandlers["/cookie2"] = _cookie2Handler;
+ _dispatchPort = new ReceivePort();
+ _dispatchPort.listen(dispatch);
}
- void dispatch(message, replyTo) {
- if (message.isStart) {
+ SendPort get dispatchSendPort => _dispatchPort.sendPort;
+
+ void dispatch(message) {
+ IsolatedHttpServerCommand command = message[0];
+ SendPort replyTo = message[1];
+ if (command.isStart) {
try {
HttpServer.bind("127.0.0.1", 0).then((server) {
_server = server;
@@ -215,11 +225,11 @@ class TestServer {
} catch (e) {
replyTo.send(new IsolatedHttpServerStatus.error(), null);
}
- } else if (message.isStop) {
+ } else if (command.isStop) {
_server.close();
- port.close();
+ _dispatchPort.close();
replyTo.send(new IsolatedHttpServerStatus.stopped(), null);
- } else if (message.isChunkedEncoding) {
+ } else if (command.isChunkedEncoding) {
_chunkedEncoding = true;
}
}
@@ -234,6 +244,7 @@ class TestServer {
}
HttpServer _server; // HTTP server instance.
+ ReceivePort _dispatchPort;
Map _requestHandlers;
bool _chunkedEncoding = false;
}
« no previous file with comments | « tests/standalone/io/echo_server_stream_test.dart ('k') | tests/standalone/io/http_basic_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698