Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(938)

Side by Side Diff: pkg/mdns/lib/src/lookup_resolver.dart

Issue 1426863003: Add a mDNS package (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: Addressed review comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
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.
4
5 library mdns.src.lookup_resolver;
6
7 import 'dart:async';
8 import 'dart:collection';
9
10 import 'package:mdns/src/packet.dart';
11
12 class PendingRequest extends LinkedListEntry {
13 final String hostname;
14 final Completer completer;
15 PendingRequest(this.hostname, this.completer);
16 }
17
18 /// Class for keeping track of pending lookups and process incoming
19 /// query responses.
20 ///
21 /// Currently the responses are no cached.
22 class LookupResolver {
23 LinkedList pendingRequests = new LinkedList();
24
25 Future addPendingRequest(String hostname, Duration timeout) {
26 var completer = new Completer();
27 var request = new PendingRequest(hostname, completer);
28 pendingRequests.add(request);
29 return completer.future.timeout(timeout, onTimeout: () {
30 request.unlink();
31 return null;
32 });
33 }
34
35 void handleResponse(List<DecodeResult> response) {
36 for (var r in response) {
37 pendingRequests
38 .where((pendingRequest) => pendingRequest.hostname == r.name)
39 .forEach((pendingRequest) {
40 pendingRequest.completer.complete(r.address);
41 pendingRequest.unlink();
42 });
43 }
44 }
45 }
46
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698