Files
sdk/tests/standalone/io/testing_server.dart
T
sgjesse@google.com 2fdb878ebe Change the signature for all network bind calls.
All the bind calls on RawServerSocket, ServerSocket,
RawSecureServerSocket, SecureServerSocket and HttpServer (and
bindSecure on HttpServer) now have mandatory address and port
parameters. All the rest of the parameters are named optional
(including backlog).

The address parameter can be an InternetAddress or a String for all
these calls.

R=ajohnsen@google.com, whesse@google.com
BUG=

Review URL: https://codereview.chromium.org//14640008

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@22227 260f80e4-7a28-3924-810f-c04153c831b5
2013-05-01 09:14:04 +00:00

67 lines
1.6 KiB
Dart

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of ServerTest;
abstract class TestingServer {
static const HOST = "127.0.0.1";
static const INIT = 0;
static const SHUTDOWN = -1;
void onConnection(Socket connection); // Abstract.
void errorHandlerServer(e) {
String msg = "Server socket error $e";
var trace = getAttachedStackTrace(e);
if (trace != null) msg += "\nStackTrace: $trace";
Expect.fail(msg);
}
void dispatch(message, SendPort replyTo) {
if (message == INIT) {
ServerSocket.bind(HOST, 0).then((server) {
_server = server;
_server.listen(
onConnection,
onError: errorHandlerServer);
replyTo.send(_server.port, null);
});
} else if (message == SHUTDOWN) {
_server.close();
port.close();
}
}
ServerSocket _server;
}
abstract class TestingServerTest {
TestingServerTest.start(SendPort port)
: _receivePort = new ReceivePort(),
_sendPort = port {
initialize();
}
void run(); // Abstract.
void initialize() {
_receivePort.receive((var message, SendPort replyTo) {
_port = message;
run();
});
_sendPort.send(TestingServer.INIT, _receivePort.toSendPort());
}
void shutdown() {
_sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort());
_receivePort.close();
}
int _port;
ReceivePort _receivePort;
SendPort _sendPort;
}