mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 17:24:20 +00:00
b101a7d002
Change-Id: Ib33169c3e0ffc870915c189404074a1dea472546 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196548 Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Leaf Petersen <leafp@google.com>
77 lines
2.2 KiB
Dart
77 lines
2.2 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.
|
|
//
|
|
|
|
// @dart = 2.9
|
|
|
|
import 'dart:async';
|
|
import 'dart:io';
|
|
import "package:expect/expect.dart";
|
|
|
|
const int serversCount = 10;
|
|
|
|
void main(List<String> args) {
|
|
if (args.isEmpty) {
|
|
for (int i = 0; i < serversCount; ++i) {
|
|
makeServer().then((server) {
|
|
runClientProcess(server.port).then((_) => server.close());
|
|
});
|
|
}
|
|
} else if (args[0] == '--client') {
|
|
int port = int.parse(args[1]);
|
|
runClient(port);
|
|
} else {
|
|
Expect.fail('Unknown arguments to raw_socket_cross_process_test.dart');
|
|
}
|
|
}
|
|
|
|
Future makeServer() {
|
|
return RawServerSocket.bind(InternetAddress.loopbackIPv4, 0).then((server) {
|
|
server.listen((connection) {
|
|
connection.writeEventsEnabled = false;
|
|
connection.listen((event) {
|
|
switch (event) {
|
|
case RawSocketEvent.read:
|
|
Expect.fail("No read event expected");
|
|
break;
|
|
case RawSocketEvent.readClosed:
|
|
connection.shutdown(SocketDirection.send);
|
|
break;
|
|
case RawSocketEvent.write:
|
|
Expect.fail("No write event expected");
|
|
break;
|
|
}
|
|
});
|
|
});
|
|
return server;
|
|
});
|
|
}
|
|
|
|
Future runClientProcess(int port) {
|
|
return Process
|
|
.run(
|
|
Platform.executable,
|
|
[]
|
|
..addAll(Platform.executableArguments)
|
|
..add(Platform.script.toFilePath())
|
|
..add('--client')
|
|
..add(port.toString()))
|
|
.then((ProcessResult result) {
|
|
if (result.exitCode != 0 || !result.stdout.contains('SUCCESS')) {
|
|
print("Client failed, exit code ${result.exitCode}");
|
|
print(" stdout:");
|
|
print(result.stdout);
|
|
print(" stderr:");
|
|
print(result.stderr);
|
|
Expect.fail('Client subprocess exit code: ${result.exitCode}');
|
|
}
|
|
});
|
|
}
|
|
|
|
runClient(int port) {
|
|
RawSocket.connect(InternetAddress.loopbackIPv4, port).then((connection) {
|
|
connection.listen((_) {}, onDone: () => print('SUCCESS'));
|
|
connection.shutdown(SocketDirection.send);
|
|
});
|
|
}
|