@@ -247,6 +247,31 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
247247 args.GetReturnValue ().Set (Array::New (isolate, result.data (), result.size ()));
248248}
249249
250+ static void GetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
251+ Environment* env = Environment::GetCurrent (args);
252+ uv_interface_address_t * interfaces;
253+ int count, i;
254+
255+ int err = uv_interface_addresses (&interfaces, &count);
256+
257+ if (err == UV_ENOSYS) return args.GetReturnValue ().Set (false );
258+
259+ if (err) {
260+ CHECK_GE (args.Length (), 1 );
261+ env->CollectUVExceptionInfo (
262+ args[args.Length () - 1 ], errno, " uv_interface_addresses" );
263+ return args.GetReturnValue ().Set (false );
264+ }
265+
266+ for (i = 0 ; i < count; i++) {
267+ if (interfaces[i].is_internal == false ) {
268+ return args.GetReturnValue ().Set (true );
269+ }
270+ }
271+
272+ uv_free_interface_addresses (interfaces, count);
273+ return args.GetReturnValue ().Set (false );
274+ }
250275
251276static void GetHomeDirectory (const FunctionCallbackInfo<Value>& args) {
252277 Environment* env = Environment::GetCurrent (args);
@@ -403,6 +428,7 @@ void Initialize(Local<Object> target,
403428 SetMethod (context, target, " getPriority" , GetPriority);
404429 SetMethod (
405430 context, target, " getAvailableParallelism" , GetAvailableParallelism);
431+ SetMethod (context, target, " getOnLineStatus" , GetOnLineStatus);
406432 SetMethod (context, target, " getOSInformation" , GetOSInformation);
407433 target
408434 ->Set (context,
@@ -419,6 +445,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
419445 registry->Register (GetFreeMemory);
420446 registry->Register (GetCPUInfo);
421447 registry->Register (GetInterfaceAddresses);
448+ registry->Register (GetOnLineStatus);
422449 registry->Register (GetHomeDirectory);
423450 registry->Register (GetUserInfo);
424451 registry->Register (SetPriority);
0 commit comments