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

Side by Side 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, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
Bill Hesse 2015/03/03 16:17:45 2015
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // This test checks that a shutdown(SocketDirection.SEND) of a socket,
6 // when the other end is already closed, does not discard unread data
7 // that remains in the connection.
8
9 import "dart:io";
10 import "dart:async";
11 import "package:expect/expect.dart";
12
13 RawServerSocket server;
14 RawSocket client;
15 Duration delay = new Duration(seconds: 1);
16
17 void serverListen(RawSocket serverSide) {
18 var data = new List.generate(200, (i) => i % 20 + 65);
19 var offset = 0;
20 void serveData(RawSocketEvent event) {
21 if (event == RawSocketEvent.WRITE) {
22 while (offset < data.length) {
23 var written = serverSide.write(data, offset);
24 offset += written;
25 if (written == 0) {
26 serverSide.writeEventsEnabled = true;
27 return;
28 }
29 }
30 serverSide.close();
31 server.close();
32 }
33 }
34 serverSide.listen(serveData);
35 }
36
37
38 void clientListen(RawSocketEvent event) {
39 if (event == RawSocketEvent.READ) {
40 client.readEventsEnabled = false;
41 new Future.delayed(delay, () {
42 var data = client.read(100);
43 Expect.isNotNull(data);
44 client.shutdown(SocketDirection.SEND);
45 data = client.read(100);
46 Expect.isNotNull(data);
47 client.close();
48 });
49 }
50 }
51
52
53 test() async {
54 server = await RawServerSocket.bind("localhost", 1968);
55 server.listen(serverListen);
56 client = await RawSocket.connect("localhost", 1968);
57 client.listen(clientListen);
58 }
59
60
61 void main() {
62 test();
63 }
OLDNEW
« 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