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

Side by Side Diff: dart/tests/standalone/io/regress_21160_test.dart

Issue 615923002: Fix circular ringbuffer used in socket implementation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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 | « dart/sdk/lib/io/secure_socket.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
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 import "package:expect/expect.dart";
6 import "package:path/path.dart";
7 import "package:async_helper/async_helper.dart";
8
9 import "dart:async";
10 import "dart:io";
11 import "dart:typed_data";
12
13 // 1 MB of i%256 data.
14 Uint8List DATA = new Uint8List.fromList(
15 new List.generate(1024 * 1024, (i) => i % 256));
16
17 Future<SecureServerSocket> startServer() {
18 return SecureServerSocket.bind("localhost",
19 0,
20 'localhost_cert').then((server) {
21 server.listen((SecureSocket request) {
22 request.drain().then((_) {
23 request
24 ..add(DATA)
25 ..close();
26 });
27 });
28 return server;
29 });
30 }
31
32 void InitializeSSL() {
33 var testPkcertDatabase = Platform.script.resolve('pkcert').toFilePath();
34 SecureSocket.initialize(database: testPkcertDatabase,
35 password: 'dartdart');
36 }
37
38 void main() {
39 InitializeSSL();
40
41 asyncStart();
42 startServer().then((SecureServerSocket server) {
43 RawSecureSocket.connect("localhost", server.port).then((socket) {
44 List<int> body = <int>[];
45
46 // Close our end, since we're not sending data.
47 socket.shutdown(SocketDirection.SEND);
48
49 socket.listen((RawSocketEvent event) {
50 switch (event) {
51 case RawSocketEvent.READ:
52 // NOTE: We have a very low prime number here. The internal
53 // ring buffers will not have a size of 3. This means that
54 // we'll reach the point where we would like to read 1/2 bytes
55 // at the end and then wrap around and read the next 2/1 bytes.
56 // [This will ensure we trigger the bug.]
57 body.addAll(socket.read(3));
58 break;
59 case RawSocketEvent.WRITE:
60 break;
61 case RawSocketEvent.READ_CLOSED:
62 break;
63 default: throw "Unexpected event $event";
64 }
65 },
66 onError: (e, _) {
67 Expect.fail('Unexpected error: $e');
68 },
69 onDone: () {
70 Expect.equals(body.length, DATA.length);
71 for (int i = 0; i < body.length; i++) {
72 Expect.equals(body[i], DATA[i]);
73 }
74 server.close();
75 asyncEnd();
76 });
77 });
78 });
79 }
OLDNEW
« no previous file with comments | « dart/sdk/lib/io/secure_socket.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698