| 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 ServerTest; | 5 part of ServerTest; |
| 6 | 6 |
| 7 abstract class TestingServer { | 7 abstract class TestingServer { |
| 8 | 8 |
| 9 static const HOST = "127.0.0.1"; | 9 static const HOST = "127.0.0.1"; |
| 10 static const INIT = 0; | 10 static const INIT = 0; |
| 11 static const SHUTDOWN = -1; | 11 static const SHUTDOWN = -1; |
| 12 | 12 |
| 13 void onConnection(Socket connection); // Abstract. | 13 void onConnection(Socket connection); // Abstract. |
| 14 | 14 |
| 15 void errorHandlerServer(e) { | 15 void errorHandlerServer(e) { |
| 16 String msg = "Server socket error $e"; | 16 String msg = "Server socket error $e"; |
| 17 var trace = getAttachedStackTrace(e); | 17 var trace = getAttachedStackTrace(e); |
| 18 if (trace != null) msg += "\nStackTrace: $trace"; | 18 if (trace != null) msg += "\nStackTrace: $trace"; |
| 19 Expect.fail(msg); | 19 Expect.fail(msg); |
| 20 } | 20 } |
| 21 | 21 |
| 22 void dispatch(message, SendPort replyTo) { | 22 void dispatch(message, SendPort replyTo) { |
| 23 if (message == INIT) { | 23 if (message == INIT) { |
| 24 ServerSocket.bind(HOST, 0, 10).then((server) { | 24 ServerSocket.bind(HOST, 0).then((server) { |
| 25 _server = server; | 25 _server = server; |
| 26 _server.listen( | 26 _server.listen( |
| 27 onConnection, | 27 onConnection, |
| 28 onError: errorHandlerServer); | 28 onError: errorHandlerServer); |
| 29 replyTo.send(_server.port, null); | 29 replyTo.send(_server.port, null); |
| 30 }); | 30 }); |
| 31 } else if (message == SHUTDOWN) { | 31 } else if (message == SHUTDOWN) { |
| 32 _server.close(); | 32 _server.close(); |
| 33 port.close(); | 33 port.close(); |
| 34 } | 34 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 57 | 57 |
| 58 void shutdown() { | 58 void shutdown() { |
| 59 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); | 59 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); |
| 60 _receivePort.close(); | 60 _receivePort.close(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 int _port; | 63 int _port; |
| 64 ReceivePort _receivePort; | 64 ReceivePort _receivePort; |
| 65 SendPort _sendPort; | 65 SendPort _sendPort; |
| 66 } | 66 } |
| OLD | NEW |