Chromium Code Reviews| Index: tests/standalone/io/issue_22637_test.dart |
| diff --git a/tests/standalone/io/issue_22637_test.dart b/tests/standalone/io/issue_22637_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..274d789e48b012b5581e236273956006f58e15ad |
| --- /dev/null |
| +++ b/tests/standalone/io/issue_22637_test.dart |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2015, 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. |
| +// |
| +// This test checks that a shutdown(SocketDirection.SEND) of a socket, |
| +// when the other end is already closed, does not discard unread data |
| +// that remains in the connection. |
| + |
| +import "dart:io"; |
| +import "dart:async"; |
| +import "package:expect/expect.dart"; |
| + |
| +RawServerSocket server; |
| +RawSocket client; |
| +Duration delay = new Duration(seconds: 1); |
| + |
| +void serverListen(RawSocket serverSide) { |
| + var data = new List.generate(200, (i) => i % 20 + 65); |
| + var offset = 0; |
| + void serveData(RawSocketEvent event) { |
| + if (event == RawSocketEvent.WRITE) { |
| + while (offset < data.length) { |
| + var written = serverSide.write(data, offset); |
| + offset += written; |
| + if (written == 0) { |
| + serverSide.writeEventsEnabled = true; |
| + return; |
| + } |
| + } |
| + serverSide.close(); |
| + server.close(); |
| + } |
| + } |
| + serverSide.listen(serveData); |
| +} |
| + |
| + |
| +void clientListen(RawSocketEvent event) { |
| + if (event == RawSocketEvent.READ) { |
| + client.readEventsEnabled = false; |
| + new Future.delayed(delay, () { |
| + var data = client.read(100); |
| + if (data == null) { |
| + // If there is no data ready to read, wait until there is data |
| + // that can be read, before running the rest of the test. |
| + client.readEventsEnabled = true; |
| + return; |
| + } |
| + client.shutdown(SocketDirection.SEND); |
| + data = client.read(100); |
| + Expect.isNotNull(data); |
| + client.close(); |
| + }); |
| + } |
| +} |
| + |
| + |
| +test() async { |
| + server = await RawServerSocket.bind("localhost", 0); |
|
Søren Gjesse
2015/03/04 13:28:15
'localhost' -> InternetAddress.IP_V4_LOOPBACK
Bill Hesse
2015/03/04 14:36:42
Done.
|
| + server.listen(serverListen); |
| + client = await RawSocket.connect("localhost", server.port); |
| + client.listen(clientListen); |
| +} |
| + |
| + |
| +void main() { |
| + test(); |
| +} |