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

Unified Diff: pkg/mdns/lib/src/native_extension_client.dart

Issue 1413713011: Revert "Extend the mDNS package with a native extension used on Mac OS" (Closed) Base URL: git@github.com:dart-lang/fletch.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/mdns/lib/src/lookup_resolver.dart ('k') | pkg/mdns/lib/src/native_protocol_client.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/mdns/lib/src/native_extension_client.dart
diff --git a/pkg/mdns/lib/src/native_extension_client.dart b/pkg/mdns/lib/src/native_extension_client.dart
deleted file mode 100644
index 3e98baaca7c16533645caafb8388f385c4a6c619..0000000000000000000000000000000000000000
--- a/pkg/mdns/lib/src/native_extension_client.dart
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright (c) 2015, the Fletch project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE.md file.
-
-library mdns.src.native_extension_client;
-
-import 'dart:async';
-import 'dart:io';
-import 'dart:isolate';
-
-import 'package:mdns/mdns.dart';
-import 'package:mdns/src/lookup_resolver.dart';
-import 'package:mdns/src/packet.dart';
-
-import "dart-ext:../native/mdns_extension_lib";
-
-// Requests Ids. This should be aligned with the C code.
-enum RequestType {
- echoRequest, // 0
- lookupRequest, // 1
-}
-
-// Implementation of mDNS client using a native extension.
-class NativeExtensionMDnsClient implements MDnsClient {
- bool _starting = false;
- bool _started = false;
- SendPort _service;
- ReceivePort _incoming;
- final LookupResolver _resolver = new LookupResolver();
-
- /// Start the mDNS client.
- Future start() async {
- if (_started && _starting) {
- throw new StateError('mDNS client already started');
- }
- _starting = true;
-
- _service = servicePort();
- _incoming = new ReceivePort();
- _incoming.listen(_handleIncoming);
-
- _starting = false;
- _started = true;
- }
-
- void stop() {
- if (!_started) return;
- if (_starting) {
- throw new StateError('Cannot stop mDNS client wile it is starting');
- }
-
- _incoming.close();
-
- _started = false;
- }
-
- Future<InternetAddress> lookup(
- String hostname, {Duration timeout: const Duration(seconds: 5)}) {
- if (!_started) {
- throw new StateError('mDNS client is not started');
- }
-
- // Add the pending request before sending the query.
- var future = _resolver.addPendingRequest(hostname, timeout);
-
- // Send the request.
- _service.send([_incoming.sendPort,
- RequestType.lookupRequest.index,
- hostname]);
-
- return future;
- }
-
- // Process incoming responses.
- _handleIncoming(response) {
- // Right not the only response we can get is the response to a
- // lookupRequest where the response looks like this:
- //
- // response[0]: hostname (String)
- // response[1]: IPv4 address (Uint8List)
- if (response is List && response.length == 2) {
- if (response[0] is String &&
- response[1] is List && response[1].length == 4) {
- response = new DecodeResult(response[0],
- new InternetAddress(response[1].join('.')));
- _resolver.handleResponse([response]);
- } else {
- // TODO(sgjesse): Improve the error handling.
- print('mDNS Response not understood');
- }
- }
- }
-}
-
-Future nativeExtensionEchoTest(dynamic message) async {
- SendPort service = servicePort();
- ReceivePort port = new ReceivePort();
- try {
- service.send([port.sendPort, RequestType.echoRequest.index, message]);
- return await port.first;
- } finally {
- port.close();
- }
-}
-
-SendPort servicePort() native 'MDnsExtension_ServicePort';
« no previous file with comments | « pkg/mdns/lib/src/lookup_resolver.dart ('k') | pkg/mdns/lib/src/native_protocol_client.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698