-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vm/io] Fix an exception when attempting to immediately cancel socket…
… connection. Fixes dartbug.com/45047 Change-Id: Ie4630684722e8c17cbc3766f91111b2a76bce7c1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186641 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Siva Annamalai <[email protected]>
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Verify that socket connection gracefully closes if cancelled. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
void main() async { | ||
final task = await Socket.startConnect('google.com', 80); | ||
task.cancel(); | ||
try { | ||
await task.socket; | ||
} catch (e) { | ||
Expect.isTrue(e is SocketException); | ||
final socketException = e as SocketException; | ||
Expect.isTrue( | ||
socketException.message.startsWith('Connection attempt cancelled')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Verify that socket connection gracefully closes if cancelled. | ||
|
||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:expect/expect.dart'; | ||
|
||
void main() async { | ||
final task = await Socket.startConnect('google.com', 80); | ||
task.cancel(); | ||
try { | ||
await task.socket; | ||
} catch (e) { | ||
Expect.isTrue(e is SocketException); | ||
final socketException = e as SocketException; | ||
Expect.isTrue( | ||
socketException.message.startsWith('Connection attempt cancelled')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters