-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[io/socket/win] Ensure udp sockets survive sending data to unreachabl…
…e destination. TEST=tests\standalone\io\socket_udp_readwrite_test.dart BUG=flutter/flutter#155823 Change-Id: Ic38bc9c022fe3964bcca003bf498c4a5435d5104 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390140 Commit-Queue: Alexander Aprelev <aam@google.com> Reviewed-by: Siva Annamalai <asiva@google.com>
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// Test writing to unreachable udp socket doesn't cause problems. | ||
|
||
import 'dart:typed_data'; | ||
import 'dart:io'; | ||
|
||
import "package:expect/expect.dart"; | ||
|
||
main() async { | ||
var _socket = await RawDatagramSocket.bind(InternetAddress.anyIPv4, 9099); | ||
_socket.listen((RawSocketEvent event) { | ||
print("event: $event"); | ||
switch (event) { | ||
case RawSocketEvent.read: | ||
Datagram? d = _socket.receive(); | ||
if (d != null) { | ||
print("recv: $d, all done"); | ||
_socket.close(); | ||
} | ||
break; | ||
case RawSocketEvent.write: | ||
print('received write event $event'); | ||
break; | ||
} | ||
}, onError: (e) { | ||
Expect.fail('Should be no exceptions, but got $e'); | ||
}); | ||
|
||
for (int i = 0; i < 100; i++) { | ||
_socket.send(Uint8List(10), InternetAddress("127.0.0.1"), 9100); | ||
} | ||
_socket.send(Uint8List(10), InternetAddress("127.0.0.1"), 9099); | ||
} |