| OLD | NEW |
| 1 // Copyright (c) 2012, 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(Exception e) { | 15 void errorHandlerServer(e) { |
| 16 Expect.fail("Server socket error $e"); | 16 Expect.fail("Server socket error $e"); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void dispatch(message, SendPort replyTo) { | 19 void dispatch(message, SendPort replyTo) { |
| 20 if (message == INIT) { | 20 if (message == INIT) { |
| 21 _server = new ServerSocket(HOST, 0, 10); | 21 ServerSocket.bind(HOST, 0, 10).then((server) { |
| 22 Expect.equals(true, _server != null); | 22 _server = server; |
| 23 _server.onConnection = onConnection; | 23 _server.listen( |
| 24 _server.onError = errorHandlerServer; | 24 onConnection, |
| 25 replyTo.send(_server.port, null); | 25 onError: errorHandlerServer); |
| 26 replyTo.send(_server.port, null); |
| 27 }); |
| 26 } else if (message == SHUTDOWN) { | 28 } else if (message == SHUTDOWN) { |
| 27 _server.close(); | 29 _server.close(); |
| 28 port.close(); | 30 port.close(); |
| 29 } | 31 } |
| 30 } | 32 } |
| 31 | 33 |
| 32 ServerSocket _server; | 34 ServerSocket _server; |
| 33 } | 35 } |
| 34 | 36 |
| 35 abstract class TestingServerTest { | 37 abstract class TestingServerTest { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 52 | 54 |
| 53 void shutdown() { | 55 void shutdown() { |
| 54 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); | 56 _sendPort.send(TestingServer.SHUTDOWN, _receivePort.toSendPort()); |
| 55 _receivePort.close(); | 57 _receivePort.close(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 int _port; | 60 int _port; |
| 59 ReceivePort _receivePort; | 61 ReceivePort _receivePort; |
| 60 SendPort _sendPort; | 62 SendPort _sendPort; |
| 61 } | 63 } |
| OLD | NEW |