OLD | NEW |
(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 } |
OLD | NEW |