New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect behavior of RawDatagramSocket class any method. #31881

Open
ngolovleva opened this Issue Jan 12, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@ngolovleva

ngolovleva commented Jan 12, 2018

Usage of any method for instance of RawDatagramSocket class in some cases leads to an infinite code cycle.
The program below reproduces the problem. Note, that if method test2 is used in any method instead of method test, the program completes successfully.
The similar problem is detected when method any checks existence of events RawSocketEvent.CLOSED and RawSocketEvent.READ_CLOSED in the receiver RawDatagramSocket.

import "dart:async";
import "dart:io";

main() {
  var expectedEvent = RawSocketEvent.WRITE;
  var address = InternetAddress.LOOPBACK_IP_V4;
  RawDatagramSocket.bind(address, 0).then((producer) {
    RawDatagramSocket.bind(address, 0).then((receiver) {
      receiver.writeEventsEnabled = false;
      int sent = 0;
      int count = 0;

      new Timer.periodic(const Duration(microseconds: 1), (timer) {
        producer.send([sent], address, receiver.port);
        print('sent $sent');
        sent++;
        if (sent > 3) {
          timer.cancel();
          producer.close();
          receiver.close();
        }
      });

      bool test(x) {
        count++;
        return x == expectedEvent;
      }
      bool test2(x) {
        count++;
        var d = receiver == null ? null: receiver.receive();
        d == null ? print(x) : print('$x  ${d.data}');
        return x == expectedEvent;
      }

      receiver.any((event) => test(event)).then((value) {
        print(' value $value   count $count');
      });
    });
  });
}

Reproduced with Dart VM version: 2.0.0-dev.15.0 (Tue Jan 2 10:39:27 2018 +0100) on "linux_x64".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment