| 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 SecureServerSocket SERVER; | 17 SecureServerSocket SERVER; |
| 18 | 18 |
| 19 String localFile(path) => Platform.script.resolve(path).toFilePath(); | 19 String localFile(path) => Platform.script.resolve(path).toFilePath(); |
| 20 | 20 |
| 21 SecurityContext serverContext = new SecurityContext() | 21 SecurityContext serverContext = new SecurityContext() |
| 22 ..useCertificateChainSync(localFile('certificates/server_chain.pem')) | 22 ..useCertificateChain(localFile('certificates/server_chain.pem')) |
| 23 ..usePrivateKeySync(localFile('certificates/server_key.pem'), | 23 ..usePrivateKey(localFile('certificates/server_key.pem'), |
| 24 password: 'dartdart'); | 24 password: 'dartdart'); |
| 25 | 25 |
| 26 SecurityContext clientContext = new SecurityContext() | 26 SecurityContext clientContext = new SecurityContext() |
| 27 ..setTrustedCertificatesSync(localFile('certificates/trusted_certs.pem')); | 27 ..setTrustedCertificates(localFile('certificates/trusted_certs.pem')); |
| 28 | 28 |
| 29 Future startServer() { | 29 Future startServer() { |
| 30 return SecureServerSocket.bind(HOST, 0, serverContext).then((server) { | 30 return SecureServerSocket.bind(HOST, 0, serverContext).then((server) { |
| 31 SERVER = server; | 31 SERVER = server; |
| 32 SERVER.listen((SecureSocket client) { | 32 SERVER.listen((SecureSocket client) { |
| 33 client.fold(<int>[], (message, data) => message..addAll(data)) | 33 client.fold(<int>[], (message, data) => message..addAll(data)) |
| 34 .then((message) { | 34 .then((message) { |
| 35 String received = new String.fromCharCodes(message); | 35 String received = new String.fromCharCodes(message); |
| 36 Expect.isTrue(received.contains("Hello from client ")); | 36 Expect.isTrue(received.contains("Hello from client ")); |
| 37 String name = received.substring(received.indexOf("client ") + 7); | 37 String name = received.substring(received.indexOf("client ") + 7); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 | 56 |
| 57 void main() { | 57 void main() { |
| 58 asyncStart(); | 58 asyncStart(); |
| 59 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first) | 59 InternetAddress.lookup("localhost").then((hosts) => HOST = hosts.first) |
| 60 .then((_) => startServer()) | 60 .then((_) => startServer()) |
| 61 .then((_) => ['ale', 'bar', 'che', 'den', 'els'].map(testClient)) | 61 .then((_) => ['ale', 'bar', 'che', 'den', 'els'].map(testClient)) |
| 62 .then((futures) => Future.wait(futures)) | 62 .then((futures) => Future.wait(futures)) |
| 63 .then((_) => SERVER.close()) | 63 .then((_) => SERVER.close()) |
| 64 .then((_) => asyncEnd()); | 64 .then((_) => asyncEnd()); |
| 65 } | 65 } |
| OLD | NEW |