| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 // This test checks that a shutdown(SocketDirection.SEND) of a socket, | 5 // This test checks that a shutdown(SocketDirection.SEND) of a socket, |
| 6 // when the other end is already closed, does not discard unread data | 6 // when the other end is already closed, does not discard unread data |
| 7 // that remains in the connection. | 7 // that remains in the connection. |
| 8 | 8 |
| 9 import "dart:io"; | 9 import "dart:io"; |
| 10 import "dart:async"; | 10 import "dart:async"; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 offset += written; | 24 offset += written; |
| 25 if (written == 0) { | 25 if (written == 0) { |
| 26 serverSide.writeEventsEnabled = true; | 26 serverSide.writeEventsEnabled = true; |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 serverSide.close(); | 30 serverSide.close(); |
| 31 server.close(); | 31 server.close(); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 |
| 34 serverSide.listen(serveData); | 35 serverSide.listen(serveData); |
| 35 } | 36 } |
| 36 | 37 |
| 37 | |
| 38 void clientListen(RawSocketEvent event) { | 38 void clientListen(RawSocketEvent event) { |
| 39 if (event == RawSocketEvent.READ) { | 39 if (event == RawSocketEvent.READ) { |
| 40 client.readEventsEnabled = false; | 40 client.readEventsEnabled = false; |
| 41 new Future.delayed(delay, () { | 41 new Future.delayed(delay, () { |
| 42 var data = client.read(100); | 42 var data = client.read(100); |
| 43 if (data == null) { | 43 if (data == null) { |
| 44 // If there is no data ready to read, wait until there is data | 44 // If there is no data ready to read, wait until there is data |
| 45 // that can be read, before running the rest of the test. | 45 // that can be read, before running the rest of the test. |
| 46 client.readEventsEnabled = true; | 46 client.readEventsEnabled = true; |
| 47 return; | 47 return; |
| 48 } | 48 } |
| 49 client.shutdown(SocketDirection.SEND); | 49 client.shutdown(SocketDirection.SEND); |
| 50 data = client.read(100); | 50 data = client.read(100); |
| 51 Expect.isNotNull(data); | 51 Expect.isNotNull(data); |
| 52 client.close(); | 52 client.close(); |
| 53 }); | 53 }); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 | |
| 58 test() async { | 57 test() async { |
| 59 server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); | 58 server = await RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
| 60 server.listen(serverListen); | 59 server.listen(serverListen); |
| 61 client = await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, server.port); | 60 client = await RawSocket.connect(InternetAddress.LOOPBACK_IP_V4, server.port); |
| 62 client.listen(clientListen); | 61 client.listen(clientListen); |
| 63 } | 62 } |
| 64 | 63 |
| 65 | |
| 66 void main() { | 64 void main() { |
| 67 test(); | 65 test(); |
| 68 } | 66 } |
| OLD | NEW |