Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Unified Diff: tests/standalone/io/issue_22637_test.dart

Issue 975723002: Fix issues with Socket shutdown. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/issue_22637_test.dart
diff --git a/tests/standalone/io/issue_22637_test.dart b/tests/standalone/io/issue_22637_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..1a5cf6aab7cbb05089dbd2a090041bdf86b69793
--- /dev/null
+++ b/tests/standalone/io/issue_22637_test.dart
@@ -0,0 +1,63 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
Bill Hesse 2015/03/03 16:17:45 2015
+// 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.
+//
+// This test checks that a shutdown(SocketDirection.SEND) of a socket,
+// when the other end is already closed, does not discard unread data
+// that remains in the connection.
+
+import "dart:io";
+import "dart:async";
+import "package:expect/expect.dart";
+
+RawServerSocket server;
+RawSocket client;
+Duration delay = new Duration(seconds: 1);
+
+void serverListen(RawSocket serverSide) {
+ var data = new List.generate(200, (i) => i % 20 + 65);
+ var offset = 0;
+ void serveData(RawSocketEvent event) {
+ if (event == RawSocketEvent.WRITE) {
+ while (offset < data.length) {
+ var written = serverSide.write(data, offset);
+ offset += written;
+ if (written == 0) {
+ serverSide.writeEventsEnabled = true;
+ return;
+ }
+ }
+ serverSide.close();
+ server.close();
+ }
+ }
+ serverSide.listen(serveData);
+}
+
+
+void clientListen(RawSocketEvent event) {
+ if (event == RawSocketEvent.READ) {
+ client.readEventsEnabled = false;
+ new Future.delayed(delay, () {
+ var data = client.read(100);
+ Expect.isNotNull(data);
+ client.shutdown(SocketDirection.SEND);
+ data = client.read(100);
+ Expect.isNotNull(data);
+ client.close();
+ });
+ }
+}
+
+
+test() async {
+ server = await RawServerSocket.bind("localhost", 1968);
+ server.listen(serverListen);
+ client = await RawSocket.connect("localhost", 1968);
+ client.listen(clientListen);
+}
+
+
+void main() {
+ test();
+}
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698