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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 .catchError((error) { | 57 .catchError((error) { |
58 Expect.isTrue(error is SocketException); | 58 Expect.isTrue(error is SocketException); |
59 asyncEnd(); | 59 asyncEnd(); |
60 }); | 60 }); |
61 }); | 61 }); |
62 } | 62 } |
63 | 63 |
64 void testSimpleConnect() { | 64 void testSimpleConnect() { |
65 asyncStart(); | 65 asyncStart(); |
66 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { | 66 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { |
67 server.listen((_) { }); | 67 server.listen((socket) { socket.close(); }); |
68 RawSocket.connect("127.0.0.1", server.port).then((_) { | 68 RawSocket.connect("127.0.0.1", server.port).then((socket) { |
69 server.close(); | 69 server.close(); |
| 70 socket.close(); |
70 asyncEnd(); | 71 asyncEnd(); |
71 }); | 72 }); |
72 }); | 73 }); |
73 } | 74 } |
74 | 75 |
75 void testCloseOneEnd(String toClose) { | 76 void testCloseOneEnd(String toClose) { |
76 asyncStart(); | 77 asyncStart(); |
77 Completer serverDone = new Completer(); | 78 Completer serverDone = new Completer(); |
78 Completer serverEndDone = new Completer(); | 79 Completer serverEndDone = new Completer(); |
79 Completer clientEndDone = new Completer(); | 80 Completer clientEndDone = new Completer(); |
(...skipping 26 matching lines...) Expand all Loading... |
106 server.close(); | 107 server.close(); |
107 }); | 108 }); |
108 }); | 109 }); |
109 }); | 110 }); |
110 } | 111 } |
111 | 112 |
112 void testServerListenAfterConnect() { | 113 void testServerListenAfterConnect() { |
113 asyncStart(); | 114 asyncStart(); |
114 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { | 115 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { |
115 Expect.isTrue(server.port > 0); | 116 Expect.isTrue(server.port > 0); |
116 RawSocket.connect("127.0.0.1", server.port).then((_) { | 117 RawSocket.connect("127.0.0.1", server.port).then((client) { |
117 server.listen((_) { | 118 server.listen((socket) { |
| 119 client.close(); |
118 server.close(); | 120 server.close(); |
| 121 socket.close(); |
119 asyncEnd(); | 122 asyncEnd(); |
120 }); | 123 }); |
121 }); | 124 }); |
122 }); | 125 }); |
123 } | 126 } |
124 | 127 |
125 void testSimpleReadWrite({bool dropReads}) { | 128 void testSimpleReadWrite({bool dropReads}) { |
126 // This test creates a server and a client connects. The client then | 129 // This test creates a server and a client connects. The client then |
127 // writes and the server echos. When the server has finished its | 130 // writes and the server echos. When the server has finished its |
128 // echo it half-closes. When the client gets the close event is | 131 // echo it half-closes. When the client gets the close event is |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 254 } |
252 | 255 |
253 testPauseServerSocket() { | 256 testPauseServerSocket() { |
254 const int socketCount = 10; | 257 const int socketCount = 10; |
255 var acceptCount = 0; | 258 var acceptCount = 0; |
256 var resumed = false; | 259 var resumed = false; |
257 | 260 |
258 asyncStart(); | 261 asyncStart(); |
259 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { | 262 RawServerSocket.bind(InternetAddress.LOOPBACK_IP_V4, 0).then((server) { |
260 Expect.isTrue(server.port > 0); | 263 Expect.isTrue(server.port > 0); |
261 var subscription = server.listen((_) { | 264 var subscription = server.listen((socket) { |
| 265 socket.close(); |
262 Expect.isTrue(resumed); | 266 Expect.isTrue(resumed); |
263 if (++acceptCount == socketCount) { | 267 if (++acceptCount == socketCount) { |
264 server.close(); | 268 server.close(); |
265 asyncEnd(); | 269 asyncEnd(); |
266 } | 270 } |
267 }); | 271 }); |
268 | 272 |
269 // Pause the server socket subscription and resume it after having | 273 // Pause the server socket subscription and resume it after having |
270 // connected a number client sockets. Then connect more client | 274 // connected a number client sockets. Then connect more client |
271 // sockets. | 275 // sockets. |
272 subscription.pause(); | 276 subscription.pause(); |
273 var connectCount = 0; | 277 var connectCount = 0; |
274 for (int i = 0; i < socketCount / 2; i++) { | 278 for (int i = 0; i < socketCount / 2; i++) { |
275 RawSocket.connect("127.0.0.1", server.port).then((_) { | 279 RawSocket.connect("127.0.0.1", server.port).then((socket) { |
276 if (++connectCount == socketCount / 2) { | 280 if (++connectCount == socketCount / 2) { |
277 subscription.resume(); | 281 subscription.resume(); |
278 resumed = true; | 282 resumed = true; |
279 for (int i = connectCount; i < socketCount; i++) { | 283 for (int i = connectCount; i < socketCount; i++) { |
280 RawSocket.connect("127.0.0.1", server.port).then((_) {}); | 284 RawSocket.connect("127.0.0.1", server.port).then((socket) { |
| 285 socket.close(); |
| 286 }); |
281 } | 287 } |
282 } | 288 } |
| 289 socket.close(); |
283 }); | 290 }); |
284 } | 291 } |
285 }); | 292 }); |
286 } | 293 } |
287 | 294 |
288 void testPauseSocket() { | 295 void testPauseSocket() { |
289 const messageSize = 1000; | 296 const messageSize = 1000; |
290 const loopCount = 10; | 297 const loopCount = 10; |
291 Completer connected = new Completer(); | 298 Completer connected = new Completer(); |
292 int pauseResumeCount = 0; | 299 int pauseResumeCount = 0; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 testSimpleConnect(); | 450 testSimpleConnect(); |
444 testServerListenAfterConnect(); | 451 testServerListenAfterConnect(); |
445 testSimpleReadWrite(dropReads: false); | 452 testSimpleReadWrite(dropReads: false); |
446 testSimpleReadWrite(dropReads: true); | 453 testSimpleReadWrite(dropReads: true); |
447 testPauseServerSocket(); | 454 testPauseServerSocket(); |
448 testPauseSocket(); | 455 testPauseSocket(); |
449 testSocketZone(); | 456 testSocketZone(); |
450 testSocketZoneError(); | 457 testSocketZoneError(); |
451 asyncEnd(); | 458 asyncEnd(); |
452 } | 459 } |
OLD | NEW |