19
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
22
+ #include < stdio.h>
22
23
#include " env-inl.h"
23
24
#include " node_external_reference.h"
24
25
#include " string_bytes.h"
26
+ #include " v8-fast-api-calls.h"
25
27
26
28
#ifdef __MINGW32__
27
29
# include < io.h>
@@ -247,7 +249,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
247
249
args.GetReturnValue ().Set (Array::New (isolate, result.data (), result.size ()));
248
250
}
249
251
250
- static void GetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
252
+ static void SlowGetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
251
253
Environment* env = Environment::GetCurrent (args);
252
254
uv_interface_address_t * interfaces;
253
255
int count, i;
@@ -274,6 +276,32 @@ static void GetOnLineStatus(const FunctionCallbackInfo<Value>& args) {
274
276
return args.GetReturnValue ().Set (false );
275
277
}
276
278
279
+ static bool FastGetOnLineStatus (v8::FastApiCallbackOptions& options) {
280
+ uv_interface_address_t * interfaces;
281
+ int count, i;
282
+
283
+ printf (" FastGetOnLineStatus\n " );
284
+ int err = uv_interface_addresses (&interfaces, &count);
285
+
286
+ if (err) {
287
+ options.fallback = true ;
288
+ return false ;
289
+ }
290
+
291
+ for (i = 0 ; i < count; i++) {
292
+ if (interfaces[i].is_internal == false ) {
293
+ uv_free_interface_addresses (interfaces, count);
294
+ return true ;
295
+ }
296
+ }
297
+
298
+ uv_free_interface_addresses (interfaces, count);
299
+ return false ;
300
+ }
301
+
302
+ v8::CFunction fast_get_on_line_status_ (
303
+ v8::CFunction::Make (FastGetOnLineStatus));
304
+
277
305
static void GetHomeDirectory (const FunctionCallbackInfo<Value>& args) {
278
306
Environment* env = Environment::GetCurrent (args);
279
307
char buf[PATH_MAX];
@@ -429,7 +457,11 @@ void Initialize(Local<Object> target,
429
457
SetMethod (context, target, " getPriority" , GetPriority);
430
458
SetMethod (
431
459
context, target, " getAvailableParallelism" , GetAvailableParallelism);
432
- SetMethod (context, target, " getOnLineStatus" , GetOnLineStatus);
460
+ SetFastMethod (context,
461
+ target,
462
+ " getOnLineStatus" ,
463
+ SlowGetOnLineStatus,
464
+ &fast_get_on_line_status_);
433
465
SetMethod (context, target, " getOSInformation" , GetOSInformation);
434
466
target
435
467
->Set (context,
@@ -446,7 +478,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
446
478
registry->Register (GetFreeMemory);
447
479
registry->Register (GetCPUInfo);
448
480
registry->Register (GetInterfaceAddresses);
449
- registry->Register (GetOnLineStatus);
481
+ registry->Register (SlowGetOnLineStatus);
482
+ registry->Register (FastGetOnLineStatus);
483
+ registry->Register (fast_get_on_line_status_.GetTypeInfo ());
450
484
registry->Register (GetHomeDirectory);
451
485
registry->Register (GetUserInfo);
452
486
registry->Register (SetPriority);
0 commit comments