| 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 "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 }); | 107 }); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void testConnectConsumerWriteClose() { | 110 void testConnectConsumerWriteClose() { |
| 111 // Connect socket write some data immediate close the consumer | 111 // Connect socket write some data immediate close the consumer |
| 112 // without listening on the stream. | 112 // without listening on the stream. |
| 113 ReceivePort port = new ReceivePort(); | 113 ReceivePort port = new ReceivePort(); |
| 114 ServerSocket.bind().then((server) { | 114 ServerSocket.bind().then((server) { |
| 115 server.listen((_) { }); | 115 server.listen((_) { }); |
| 116 Socket.connect("127.0.0.1", server.port).then((socket) { | 116 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 117 socket.writeBytes([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); | 117 socket.add([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); |
| 118 socket.close(); | 118 socket.close(); |
| 119 socket.done.then((_) { | 119 socket.done.then((_) { |
| 120 socket.destroy(); | 120 socket.destroy(); |
| 121 server.close(); | 121 server.close(); |
| 122 port.close(); | 122 port.close(); |
| 123 }); | 123 }); |
| 124 }); | 124 }); |
| 125 }); | 125 }); |
| 126 } | 126 } |
| 127 | 127 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 } | 149 } |
| 150 | 150 |
| 151 void testConnectStreamDataClose(bool useDestroy) { | 151 void testConnectStreamDataClose(bool useDestroy) { |
| 152 // Connect socket and listen on the stream. The server sends data | 152 // Connect socket and listen on the stream. The server sends data |
| 153 // and then closes so both data and a done event is received. | 153 // and then closes so both data and a done event is received. |
| 154 List<int> sendData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 154 List<int> sendData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 155 ReceivePort port = new ReceivePort(); | 155 ReceivePort port = new ReceivePort(); |
| 156 ServerSocket.bind().then((server) { | 156 ServerSocket.bind().then((server) { |
| 157 server.listen( | 157 server.listen( |
| 158 (client) { | 158 (client) { |
| 159 client.writeBytes(sendData); | 159 client.add(sendData); |
| 160 if (useDestroy) { | 160 if (useDestroy) { |
| 161 client.destroy(); | 161 client.destroy(); |
| 162 } else { | 162 } else { |
| 163 client.close(); | 163 client.close(); |
| 164 } | 164 } |
| 165 client.done.then((_) { if (!useDestroy) { client.destroy(); } }); | 165 client.done.then((_) { if (!useDestroy) { client.destroy(); } }); |
| 166 }); | 166 }); |
| 167 Socket.connect("127.0.0.1", server.port).then((socket) { | 167 Socket.connect("127.0.0.1", server.port).then((socket) { |
| 168 List<int> data = []; | 168 List<int> data = []; |
| 169 bool onDoneCalled = false; | 169 bool onDoneCalled = false; |
| 170 socket.listen(data.addAll, | 170 socket.listen(data.addAll, |
| 171 onDone: () { | 171 onDone: () { |
| 172 Expect.isFalse(onDoneCalled); | 172 Expect.isFalse(onDoneCalled); |
| 173 onDoneCalled = true; | 173 onDoneCalled = true; |
| 174 if (!useDestroy) Expect.listEquals(sendData, data); | 174 if (!useDestroy) Expect.listEquals(sendData, data); |
| 175 socket.writeBytes([0]); | 175 socket.add([0]); |
| 176 socket.close(); | 176 socket.close(); |
| 177 server.close(); | 177 server.close(); |
| 178 port.close(); | 178 port.close(); |
| 179 }); | 179 }); |
| 180 }); | 180 }); |
| 181 }); | 181 }); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void testConnectStreamDataCloseCancel(bool useDestroy) { | 184 void testConnectStreamDataCloseCancel(bool useDestroy) { |
| 185 List<int> sendData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | 185 List<int> sendData = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; |
| 186 ReceivePort port = new ReceivePort(); | 186 ReceivePort port = new ReceivePort(); |
| 187 ServerSocket.bind().then((server) { | 187 ServerSocket.bind().then((server) { |
| 188 server.listen( | 188 server.listen( |
| 189 (client) { | 189 (client) { |
| 190 client.writeBytes(sendData); | 190 client.add(sendData); |
| 191 if (useDestroy) { | 191 if (useDestroy) { |
| 192 client.destroy(); | 192 client.destroy(); |
| 193 } else { | 193 } else { |
| 194 client.close(); | 194 client.close(); |
| 195 } | 195 } |
| 196 client.done | 196 client.done |
| 197 .then((_) { | 197 .then((_) { |
| 198 if (!useDestroy) client.destroy(); | 198 if (!useDestroy) client.destroy(); |
| 199 }) | 199 }) |
| 200 .catchError((e) { /* can happen with short writes */ }); | 200 .catchError((e) { /* can happen with short writes */ }); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 222 testConnectNoDestroy(); | 222 testConnectNoDestroy(); |
| 223 testConnectImmediateDestroy(); | 223 testConnectImmediateDestroy(); |
| 224 testConnectConsumerClose(); | 224 testConnectConsumerClose(); |
| 225 testConnectConsumerWriteClose(); | 225 testConnectConsumerWriteClose(); |
| 226 testConnectStreamClose(); | 226 testConnectStreamClose(); |
| 227 testConnectStreamDataClose(true); | 227 testConnectStreamDataClose(true); |
| 228 testConnectStreamDataClose(false); | 228 testConnectStreamDataClose(false); |
| 229 testConnectStreamDataCloseCancel(true); | 229 testConnectStreamDataCloseCancel(true); |
| 230 testConnectStreamDataCloseCancel(false); | 230 testConnectStreamDataCloseCancel(false); |
| 231 } | 231 } |
| OLD | NEW |