| 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 library scheduled_test.scheduled_server; | 5 library scheduled_test.scheduled_server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'dart:uri'; | 10 import 'dart:uri'; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 /// Creates a new server listening on an automatically-allocated port on | 42 /// Creates a new server listening on an automatically-allocated port on |
| 43 /// localhost. [description] is used to refer to the server in debugging | 43 /// localhost. [description] is used to refer to the server in debugging |
| 44 /// messages. | 44 /// messages. |
| 45 factory ScheduledServer([String description]) { | 45 factory ScheduledServer([String description]) { |
| 46 var id = _count++; | 46 var id = _count++; |
| 47 if (description == null) description = 'scheduled server $id'; | 47 if (description == null) description = 'scheduled server $id'; |
| 48 | 48 |
| 49 var scheduledServer; | 49 var scheduledServer; |
| 50 scheduledServer = new ScheduledServer._(schedule(() { | 50 scheduledServer = new ScheduledServer._(schedule(() { |
| 51 return SafeHttpServer.bind("127.0.0.1", 0).then((server) { | 51 return SafeHttpServer.bind("localhost", 0).then((server) { |
| 52 server.listen(scheduledServer._handleRequest, | 52 server.listen(scheduledServer._handleRequest, |
| 53 onError: (e) => currentSchedule.signalError(e)); | 53 onError: (e) => currentSchedule.signalError(e)); |
| 54 currentSchedule.onComplete.schedule(server.close); | 54 currentSchedule.onComplete.schedule(server.close); |
| 55 return server; | 55 return server; |
| 56 }); | 56 }); |
| 57 }, "starting '$description'"), description); | 57 }, "starting '$description'"), description); |
| 58 return scheduledServer; | 58 return scheduledServer; |
| 59 } | 59 } |
| 60 | 60 |
| 61 /// The port on which the server is listening. | 61 /// The port on which the server is listening. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 "when no more requests were expected."; | 97 "when no more requests were expected."; |
| 98 } | 98 } |
| 99 return _handlers.removeFirst().fn(request); | 99 return _handlers.removeFirst().fn(request); |
| 100 }).catchError((e) { | 100 }).catchError((e) { |
| 101 // Close the server so that we don't leave a dangling request. | 101 // Close the server so that we don't leave a dangling request. |
| 102 _server.then((s) => s.close()); | 102 _server.then((s) => s.close()); |
| 103 throw e; | 103 throw e; |
| 104 }), 'receiving ${request.method} ${request.uri}'); | 104 }), 'receiving ${request.method} ${request.uri}'); |
| 105 } | 105 } |
| 106 } | 106 } |
| OLD | NEW |