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