| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test socket close events. | 5 // Test socket close events. |
| 6 | 6 |
| 7 | 7 |
| 8 final SERVERSHUTDOWN = -1; | 8 final SERVERSHUTDOWN = -1; |
| 9 final ITERATIONS = 10; | 9 final ITERATIONS = 10; |
| 10 | 10 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 202 } |
| 203 | 203 |
| 204 class SocketCloseServer extends Isolate { | 204 class SocketCloseServer extends Isolate { |
| 205 | 205 |
| 206 static final HOST = "127.0.0.1"; | 206 static final HOST = "127.0.0.1"; |
| 207 | 207 |
| 208 SocketCloseServer() : super() {} | 208 SocketCloseServer() : super() {} |
| 209 | 209 |
| 210 void main() { | 210 void main() { |
| 211 | 211 |
| 212 void connectionHandler() { | 212 void connectionHandler(Socket connection) { |
| 213 Socket _client; | |
| 214 | 213 |
| 215 void dataHandler() { | 214 void dataHandler() { |
| 216 _dataEvents++; | 215 _dataEvents++; |
| 217 switch (_mode) { | 216 switch (_mode) { |
| 218 case 0: | 217 case 0: |
| 219 Expect.fail("No data expected"); | 218 Expect.fail("No data expected"); |
| 220 break; | 219 break; |
| 221 case 1: | 220 case 1: |
| 222 List<int> b = new List<int>(100); | 221 List<int> b = new List<int>(100); |
| 223 _client.readList(b, 0, 100); | 222 connection.readList(b, 0, 100); |
| 224 break; | 223 break; |
| 225 case 2: | 224 case 2: |
| 226 List<int> b = new List<int>(100); | 225 List<int> b = new List<int>(100); |
| 227 _client.readList(b, 0, 100); | 226 connection.readList(b, 0, 100); |
| 228 _client.close(); | 227 connection.close(); |
| 229 break; | 228 break; |
| 230 case 3: | 229 case 3: |
| 231 List<int> b = new List<int>(100); | 230 List<int> b = new List<int>(100); |
| 232 _client.readList(b, 0, 100); | 231 connection.readList(b, 0, 100); |
| 233 _client.writeList("Hello".charCodes(), 0, 5); | 232 connection.writeList("Hello".charCodes(), 0, 5); |
| 234 _client.close(); | 233 connection.close(); |
| 235 break; | 234 break; |
| 236 case 4: | 235 case 4: |
| 237 List<int> b = new List<int>(100); | 236 List<int> b = new List<int>(100); |
| 238 _client.readList(b, 0, 100); | 237 connection.readList(b, 0, 100); |
| 239 _client.writeList("Hello".charCodes(), 0, 5); | 238 connection.writeList("Hello".charCodes(), 0, 5); |
| 240 break; | 239 break; |
| 241 case 5: | 240 case 5: |
| 242 case 6: | 241 case 6: |
| 243 List<int> b = new List<int>(100); | 242 List<int> b = new List<int>(100); |
| 244 _client.readList(b, 0, 100); | 243 connection.readList(b, 0, 100); |
| 245 _client.writeList("Hello".charCodes(), 0, 5); | 244 connection.writeList("Hello".charCodes(), 0, 5); |
| 246 _client.close(true); | 245 connection.close(true); |
| 247 break; | 246 break; |
| 248 default: | 247 default: |
| 249 Expect.fail("Unknown test mode"); | 248 Expect.fail("Unknown test mode"); |
| 250 } | 249 } |
| 251 } | 250 } |
| 252 | 251 |
| 253 void closeHandler() { | 252 void closeHandler() { |
| 254 _closeEvents++; | 253 _closeEvents++; |
| 255 _client.close(); | 254 connection.close(); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void errorHandler() { | 257 void errorHandler() { |
| 259 Expect.fail("Socket error"); | 258 Expect.fail("Socket error"); |
| 260 } | 259 } |
| 261 | 260 |
| 262 _client = _server.accept(); | |
| 263 _iterations++; | 261 _iterations++; |
| 264 | 262 |
| 265 _client.dataHandler = dataHandler; | 263 connection.dataHandler = dataHandler; |
| 266 _client.closeHandler = closeHandler; | 264 connection.closeHandler = closeHandler; |
| 267 _client.errorHandler = errorHandler; | 265 connection.errorHandler = errorHandler; |
| 268 } | 266 } |
| 269 | 267 |
| 270 void errorHandlerServer() { | 268 void errorHandlerServer() { |
| 271 Expect.fail("Server socket error"); | 269 Expect.fail("Server socket error"); |
| 272 } | 270 } |
| 273 | 271 |
| 274 waitForResult(Timer timer) { | 272 waitForResult(Timer timer) { |
| 275 // Make sure all iterations have been run. For mode 0 and 1 the | 273 // Make sure all iterations have been run. For mode 0 and 1 the |
| 276 // client just closes the socket and after the last iteration | 274 // client just closes the socket and after the last iteration |
| 277 // signals the server. The server might now be finished just | 275 // signals the server. The server might now be finished just |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 int _dataEvents; | 332 int _dataEvents; |
| 335 int _closeEvents; | 333 int _closeEvents; |
| 336 int _iterations; | 334 int _iterations; |
| 337 int _mode; | 335 int _mode; |
| 338 } | 336 } |
| 339 | 337 |
| 340 | 338 |
| 341 main() { | 339 main() { |
| 342 SocketCloseTest.testMain(); | 340 SocketCloseTest.testMain(); |
| 343 } | 341 } |
| OLD | NEW |