blob: 31cca0c4dcf3a045f1477a3e861fc2bc778a9e48 [file] [log] [blame]
/*
* Copyright (c) 2018, 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.
*/
/**
* @assertion Future<int> length
* The number of elements in this stream.
*
* Waits for all elements of this stream. When the stream ends, the returned
* future is completed with the number of elements.
*
* @description Checks that property length returns the number of elements in
* the socket when this RawDatagramSocket is regarded as a broadcast stream.
* @author ngl@unipro.ru
*/
import "dart:io";
import "dart:async";
import "../../../Utils/expect.dart";
check([bool no_write_events = false]) {
asyncStart();
var address = InternetAddress.loopbackIPv4;
RawDatagramSocket.bind(address, 0).then((producer) {
RawDatagramSocket.bind(address, 0).then((receiver) {
if (no_write_events) {
receiver.writeEventsEnabled = false;
}
int sent = 0;
int counter = 0;
producer.send([sent++], address, receiver.port);
producer.send([sent++], address, receiver.port);
producer.send([sent], address, receiver.port);
producer.close();
Stream<RawSocketEvent> stream = receiver.asBroadcastStream();
stream.length.then((value) {
Expect.equals(4, value);
});
new Timer(const Duration(milliseconds: 200), () {
Expect.isNull(receiver.receive());
receiver.close();
});
stream.listen((event) {
counter++;
receiver.receive();
}).onDone(() {
Expect.equals(4, counter);
asyncEnd();
});
});
});
}
main() {
check();
check(true);
}