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_extension_client; | 5 library mdns.src.native_extension_client; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:isolate'; | 9 import 'dart:isolate'; |
10 | 10 |
(...skipping 52 matching lines...) Loading... |
63 String name, | 63 String name, |
64 {Duration timeout: const Duration(seconds: 5)}) { | 64 {Duration timeout: const Duration(seconds: 5)}) { |
65 if (!_started) { | 65 if (!_started) { |
66 throw new StateError('mDNS client is not started'); | 66 throw new StateError('mDNS client is not started'); |
67 } | 67 } |
68 | 68 |
69 // Add the pending request before sending the query. | 69 // Add the pending request before sending the query. |
70 var result = _resolver.addPendingRequest(type, name, timeout); | 70 var result = _resolver.addPendingRequest(type, name, timeout); |
71 | 71 |
72 // Send the request. | 72 // Send the request. |
| 73 // |
| 74 // response[0]: reply port (SendPort) |
| 75 // response[1]: request type (int) |
| 76 // response[2]: record type (int) |
| 77 // response[3]: data (Uint8List) |
| 78 // response[4]: timeout in milliseconds (int) |
73 _service.send([_incoming.sendPort, | 79 _service.send([_incoming.sendPort, |
74 RequestType.lookupRequest.index, | 80 RequestType.lookupRequest.index, |
75 type, | 81 type, |
76 name]); | 82 name, |
| 83 timeout.inMilliseconds]); |
77 | 84 |
78 return result; | 85 return result; |
79 } | 86 } |
80 | 87 |
81 // Process incoming responses. | 88 // Process incoming responses. |
82 _handleIncoming(response) { | 89 _handleIncoming(response) { |
83 // Right now the only response we can get is the response to a | 90 // Right now the only response we can get is the response to a |
84 // lookupRequest where the response looks like this: | 91 // lookupRequest where the response looks like this: |
85 // | 92 // |
86 // response[0]: fullname (String) | 93 // response[0]: fullname (String) |
(...skipping 49 matching lines...) Loading... |
136 await native_extension_api.loadLibrary(); | 143 await native_extension_api.loadLibrary(); |
137 SendPort service = native_extension_api.servicePort(); | 144 SendPort service = native_extension_api.servicePort(); |
138 ReceivePort port = new ReceivePort(); | 145 ReceivePort port = new ReceivePort(); |
139 try { | 146 try { |
140 service.send([port.sendPort, RequestType.echoRequest.index, message]); | 147 service.send([port.sendPort, RequestType.echoRequest.index, message]); |
141 return await port.first; | 148 return await port.first; |
142 } finally { | 149 } finally { |
143 port.close(); | 150 port.close(); |
144 } | 151 } |
145 } | 152 } |
OLD | NEW |