| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // VMOptions= | 5 // VMOptions= |
| 6 // VMOptions=--short_socket_read | 6 // VMOptions=--short_socket_read |
| 7 // VMOptions=--short_socket_write | 7 // VMOptions=--short_socket_write |
| 8 // VMOptions=--short_socket_read --short_socket_write | 8 // VMOptions=--short_socket_read --short_socket_write |
| 9 | 9 |
| 10 import "dart:async"; | 10 import "dart:async"; |
| 11 import "dart:io"; | 11 import "dart:io"; |
| 12 | 12 |
| 13 import "package:async_helper/async_helper.dart"; | 13 import "package:async_helper/async_helper.dart"; |
| 14 import "package:expect/expect.dart"; | 14 import "package:expect/expect.dart"; |
| 15 | 15 |
| 16 InternetAddress HOST; | 16 InternetAddress HOST; |
| 17 | 17 |
| 18 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 18 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 19 List<int> readLocalFile(path) => (new File(localFile(path))).readAsBytesSync(); | |
| 20 | 19 |
| 21 SecurityContext serverContext = new SecurityContext() | 20 SecurityContext serverContext = new SecurityContext() |
| 22 ..useCertificateChainBytes(readLocalFile('certificates/server_chain.pem')) | 21 ..useCertificateChainSync(localFile('certificates/server_chain.pem')) |
| 23 ..usePrivateKeyBytes(readLocalFile('certificates/server_key.pem'), | 22 ..usePrivateKeySync(localFile('certificates/server_key.pem'), |
| 24 password: 'dartdart'); | 23 password: 'dartdart'); |
| 25 | 24 |
| 26 SecurityContext clientContext = new SecurityContext() | 25 SecurityContext clientContext = new SecurityContext() |
| 27 ..setTrustedCertificates(file: localFile('certificates/trusted_certs.pem')); | 26 ..setTrustedCertificatesSync( |
| 27 localFile('certificates/trusted_certs.pem')); |
| 28 | 28 |
| 29 | 29 |
| 30 Future<SecureServerSocket> startEchoServer() { | 30 Future<SecureServerSocket> startEchoServer() { |
| 31 return SecureServerSocket.bind(HOST, | 31 return SecureServerSocket.bind(HOST, |
| 32 0, | 32 0, |
| 33 serverContext).then((server) { | 33 serverContext).then((server) { |
| 34 server.listen((SecureSocket client) { | 34 server.listen((SecureSocket client) { |
| 35 client.fold(<int>[], (message, data) => message..addAll(data)) | 35 client.fold(<int>[], (message, data) => message..addAll(data)) |
| 36 .then((message) { | 36 .then((message) { |
| 37 client.add(message); | 37 client.add(message); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 void main() { | 58 void main() { |
| 59 asyncStart(); | 59 asyncStart(); |
| 60 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first ) | 60 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first ) |
| 61 .then((_) => startEchoServer()) | 61 .then((_) => startEchoServer()) |
| 62 .then(testClient) | 62 .then(testClient) |
| 63 .then((server) => server.close()) | 63 .then((server) => server.close()) |
| 64 .then((_) => asyncEnd()); | 64 .then((_) => asyncEnd()); |
| 65 } | 65 } |
| OLD | NEW |