| 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 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 const int NUM_SERVERS = 10; | 10 const int NUM_SERVERS = 10; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } else { | 22 } else { |
| 23 Expect.fail('Unknown arguments to raw_socket_cross_process_test.dart'); | 23 Expect.fail('Unknown arguments to raw_socket_cross_process_test.dart'); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 Future makeServer() { | 27 Future makeServer() { |
| 28 return RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { | 28 return RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { |
| 29 server.listen((connection) { | 29 server.listen((connection) { |
| 30 connection.writeEventsEnabled = false; | 30 connection.writeEventsEnabled = false; |
| 31 connection.listen((event) { | 31 connection.listen((event) { |
| 32 switch(event) { | 32 switch (event) { |
| 33 case RawSocketEvent.READ: | 33 case RawSocketEvent.READ: |
| 34 Expect.fail("No read event expected"); | 34 Expect.fail("No read event expected"); |
| 35 break; | 35 break; |
| 36 case RawSocketEvent.READ_CLOSED: | 36 case RawSocketEvent.READ_CLOSED: |
| 37 connection.shutdown(SocketDirection.SEND); | 37 connection.shutdown(SocketDirection.SEND); |
| 38 break; | 38 break; |
| 39 case RawSocketEvent.WRITE: | 39 case RawSocketEvent.WRITE: |
| 40 Expect.fail("No write event expected"); | 40 Expect.fail("No write event expected"); |
| 41 break; | 41 break; |
| 42 } | 42 } |
| 43 }); | 43 }); |
| 44 }); | 44 }); |
| 45 return server; | 45 return server; |
| 46 }); | 46 }); |
| 47 } | 47 } |
| 48 | 48 |
| 49 Future runClientProcess(int port) { | 49 Future runClientProcess(int port) { |
| 50 return Process.run(Platform.executable, | 50 return Process |
| 51 []..addAll(Platform.executableArguments) | 51 .run( |
| 52 ..add(Platform.script.toFilePath()) | 52 Platform.executable, |
| 53 ..add('--client') | 53 [] |
| 54 ..add(port.toString())).then((ProcessResult result) { | 54 ..addAll(Platform.executableArguments) |
| 55 ..add(Platform.script.toFilePath()) |
| 56 ..add('--client') |
| 57 ..add(port.toString())) |
| 58 .then((ProcessResult result) { |
| 55 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) { | 59 if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) { |
| 56 print("Client failed, exit code ${result.exitCode}"); | 60 print("Client failed, exit code ${result.exitCode}"); |
| 57 print(" stdout:"); | 61 print(" stdout:"); |
| 58 print(result.stdout); | 62 print(result.stdout); |
| 59 print(" stderr:"); | 63 print(" stderr:"); |
| 60 print(result.stderr); | 64 print(result.stderr); |
| 61 Expect.fail('Client subprocess exit code: ${result.exitCode}'); | 65 Expect.fail('Client subprocess exit code: ${result.exitCode}'); |
| 62 } | 66 } |
| 63 }); | 67 }); |
| 64 } | 68 } |
| 65 | 69 |
| 66 runClient(int port) { | 70 runClient(int port) { |
| 67 RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, port).then((connection) { | 71 RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, port).then((connection) { |
| 68 connection.listen((_) { }, onDone: () => print('SUCCESS')); | 72 connection.listen((_) {}, onDone: () => print('SUCCESS')); |
| 69 connection.shutdown(SocketDirection.SEND); | 73 connection.shutdown(SocketDirection.SEND); |
| 70 }); | 74 }); |
| 71 } | 75 } |
| OLD | NEW |