mirror of
https://github.com/dart-lang/sdk
synced 2024-10-02 23:24:42 +00:00
Added timeout parameter to RawSecureSocket and SecureSocket connect methods. Also updated CHANGELOG and SecureSocket tests to reflect this change. Issue 19120.
BUG= R=zra@google.com Review-Url: https://codereview.chromium.org/2950413002 .
This commit is contained in:
parent
4f9b25e410
commit
06456e83d8
11
CHANGELOG.md
11
CHANGELOG.md
|
@ -20,11 +20,12 @@
|
|||
methods are now supported on iOS and OSX.
|
||||
* Deprecated `SecurityContext.alpnSupported` as ALPN is now supported on all
|
||||
platforms.
|
||||
* Added 'timeout' parameter to 'Socket.connect' and 'RawSocket.connect'. If a
|
||||
connection attempt takes longer than the duration specified in 'timeout', a
|
||||
'SocketException' will be thrown. Note: if the duration specified in
|
||||
'timeout' is greater than the system level timeout duration, a timeout may
|
||||
occur sooner than specified in 'timeout'.
|
||||
* Added 'timeout' parameter to 'Socket.connect', 'RawSocket.connect',
|
||||
'SecureSocket.connect' and 'RawSecureSocket.connect. If a connection attempt
|
||||
takes longer than the duration specified in 'timeout', a 'SocketException'
|
||||
will be thrown. Note: if the duration specified in 'timeout' is greater than
|
||||
the system level timeout duration, a timeout may occur sooner than specified
|
||||
in 'timeout'.
|
||||
|
||||
### Dart VM
|
||||
* Support for MIPS has been remvoed.
|
||||
|
|
|
@ -33,16 +33,25 @@ abstract class SecureSocket implements Socket {
|
|||
* order of preference) to use during the ALPN protocol negogiation with the
|
||||
* server. Example values are "http/1.1" or "h2". The selected protocol
|
||||
* can be obtained via [SecureSocket.selectedProtocol].
|
||||
*
|
||||
* The argument [timeout] is used to specify the maximum allowed time to wait
|
||||
* for a connection to be established. If [timeout] is longer than the system
|
||||
* level timeout duration, a timeout may occur sooner than specified in
|
||||
* [timeout]. On timeout, a [SocketException] is thrown and all ongoing
|
||||
* connection attempts to [host] are cancelled.
|
||||
|
||||
*/
|
||||
static Future<SecureSocket> connect(host, int port,
|
||||
{SecurityContext context,
|
||||
bool onBadCertificate(X509Certificate certificate),
|
||||
List<String> supportedProtocols}) {
|
||||
List<String> supportedProtocols,
|
||||
Duration timeout}) {
|
||||
return RawSecureSocket
|
||||
.connect(host, port,
|
||||
context: context,
|
||||
onBadCertificate: onBadCertificate,
|
||||
supportedProtocols: supportedProtocols)
|
||||
supportedProtocols: supportedProtocols,
|
||||
timeout: timeout)
|
||||
.then((rawSocket) => new SecureSocket._(rawSocket));
|
||||
}
|
||||
|
||||
|
@ -194,10 +203,11 @@ abstract class RawSecureSocket implements RawSocket {
|
|||
static Future<RawSecureSocket> connect(host, int port,
|
||||
{SecurityContext context,
|
||||
bool onBadCertificate(X509Certificate certificate),
|
||||
List<String> supportedProtocols}) {
|
||||
List<String> supportedProtocols,
|
||||
Duration timeout}) {
|
||||
_RawSecureSocket._verifyFields(
|
||||
host, port, false, false, false, onBadCertificate);
|
||||
return RawSocket.connect(host, port).then((socket) {
|
||||
return RawSocket.connect(host, port, timeout: timeout).then((socket) {
|
||||
return secure(socket,
|
||||
context: context,
|
||||
onBadCertificate: onBadCertificate,
|
||||
|
|
|
@ -80,9 +80,22 @@ Future test(String certType, String password) {
|
|||
return completer.future;
|
||||
}
|
||||
|
||||
void testConnectTimeout() {
|
||||
asyncStart();
|
||||
Duration timeout = new Duration(milliseconds: 20);
|
||||
SecureSocket.connect("8.8.8.7", 80, timeout: timeout).then((socket) {
|
||||
Expect.fail("Unexpected connection made.");
|
||||
asyncEnd();
|
||||
}).catchError((e) {
|
||||
Expect.isTrue(e is SocketException);
|
||||
asyncEnd();
|
||||
});
|
||||
}
|
||||
|
||||
main() async {
|
||||
asyncStart();
|
||||
await test('pem', 'dartdart');
|
||||
await test('p12', 'dartdart');
|
||||
testConnectTimeout();
|
||||
asyncEnd();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue