| OLD | NEW |
| 1 // Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Fletch 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library mdns.src.native_protocol_client; | 5 library mdns.src.native_protocol_client; |
| 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 | 10 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 | 125 |
| 126 Stream<ResourceRecord> lookup( | 126 Stream<ResourceRecord> lookup( |
| 127 int type, | 127 int type, |
| 128 String name, | 128 String name, |
| 129 {Duration timeout: const Duration(seconds: 5)}) { | 129 {Duration timeout: const Duration(seconds: 5)}) { |
| 130 if (!_started) { | 130 if (!_started) { |
| 131 throw new StateError('mDNS client is not started'); | 131 throw new StateError('mDNS client is not started'); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Look for entries in the cache. | 134 // Look for entries in the cache. |
| 135 List<ResourceRecordCache> cached = <ResourceRecord>[]; | 135 List<ResourceRecord> cached = <ResourceRecord>[]; |
| 136 cache.lookup(name, type, cached); | 136 cache.lookup(name, type, cached); |
| 137 if (cached.isNotEmpty) { | 137 if (cached.isNotEmpty) { |
| 138 StreamController controller = new StreamController(); | 138 StreamController controller = new StreamController(); |
| 139 cached.forEach(controller.add); | 139 cached.forEach(controller.add); |
| 140 controller.close(); | 140 controller.close(); |
| 141 return controller.stream; | 141 return controller.stream; |
| 142 } | 142 } |
| 143 | 143 |
| 144 // Add the pending request before sending the query. | 144 // Add the pending request before sending the query. |
| 145 var results = _resolver.addPendingRequest(type, name, timeout); | 145 var results = _resolver.addPendingRequest(type, name, timeout); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 158 if (event == RawSocketEvent.READ) { | 158 if (event == RawSocketEvent.READ) { |
| 159 Datagram datagram = _incoming.receive(); | 159 Datagram datagram = _incoming.receive(); |
| 160 List<ResourceRecord> response = decodeMDnsResponse(datagram.data); | 160 List<ResourceRecord> response = decodeMDnsResponse(datagram.data); |
| 161 if (response != null) { | 161 if (response != null) { |
| 162 cache.updateRecords(response); | 162 cache.updateRecords(response); |
| 163 _resolver.handleResponse(response); | 163 _resolver.handleResponse(response); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 } | 166 } |
| 167 } | 167 } |
| OLD | NEW |