| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // |
| 5 |
| 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; |
| 8 import 'dart:io'; |
| 9 |
| 10 const int NUM_SERVERS = 10; |
| 11 |
| 12 void main() { |
| 13 var args = new Options().arguments; |
| 14 if (args.isEmpty) { |
| 15 for (int i = 0; i < NUM_SERVERS; ++i) { |
| 16 makeServer().then((server) { |
| 17 runClientProcess(server.port).then((_) => server.close()); |
| 18 }); |
| 19 } |
| 20 } else if (args[0] == 'client') { |
| 21 int port = int.parse(args[1]); |
| 22 runClient(port); |
| 23 } else { |
| 24 Expect.fail('Unknown arguments to raw_socket_cross_process_test.dart'); |
| 25 } |
| 26 } |
| 27 |
| 28 Future makeServer() { |
| 29 return RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { |
| 30 server.listen((connection) { |
| 31 connection.writeEventsEnabled = false; |
| 32 connection.listen((event) { |
| 33 switch(event) { |
| 34 case RawSocketEvent.READ: |
| 35 Expect.fail("No read event expected"); |
| 36 break; |
| 37 case RawSocketEvent.READ_CLOSED: |
| 38 connection.shutdown(SocketDirection.SEND); |
| 39 break; |
| 40 case RawSocketEvent.WRITE: |
| 41 Expect.fail("No write event expected"); |
| 42 break; |
| 43 } |
| 44 }); |
| 45 }); |
| 46 return server; |
| 47 }); |
| 48 } |
| 49 |
| 50 Future runClientProcess(int port) { |
| 51 return Process.run(Platform.executable, |
| 52 []..addAll(Platform.executableArguments) |
| 53 ..add(Platform.script) |
| 54 ..add('client') |
| 55 ..add(port.toString())).then((ProcessResult result) { |
| 56 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) { |
| 57 print("Client failed, exit code ${result.exitCode}"); |
| 58 print(" stdout:"); |
| 59 print(result.stdout); |
| 60 print(" stderr:"); |
| 61 print(result.stderr); |
| 62 Expect.fail('Client subprocess exit code: ${result.exitCode}'); |
| 63 } |
| 64 }); |
| 65 } |
| 66 |
| 67 runClient(int port) { |
| 68 RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, port).then((connection) { |
| 69 connection.listen((_) { }, onDone: () => print('SUCCESS')); |
| 70 connection.shutdown(SocketDirection.SEND); |
| 71 }); |
| 72 } |
| OLD | NEW |