1919// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
2020// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121
22+ #include < stdio.h>
2223#include " env-inl.h"
2324#include " node_external_reference.h"
2425#include " string_bytes.h"
26+ #include " v8-fast-api-calls.h"
2527
2628#ifdef __MINGW32__
2729# include < io.h>
@@ -247,7 +249,7 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
247249 args.GetReturnValue ().Set (Array::New (isolate, result.data (), result.size ()));
248250}
249251
250- static void GetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
252+ static void SlowGetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
251253 Environment* env = Environment::GetCurrent (args);
252254 uv_interface_address_t * interfaces;
253255 int count, i;
@@ -274,6 +276,32 @@ static void GetOnLineStatus(const FunctionCallbackInfo<Value>& args) {
274276 return args.GetReturnValue ().Set (false );
275277}
276278
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+
277305static void GetHomeDirectory (const FunctionCallbackInfo<Value>& args) {
278306 Environment* env = Environment::GetCurrent (args);
279307 char buf[PATH_MAX];
@@ -429,7 +457,11 @@ void Initialize(Local<Object> target,
429457 SetMethod (context, target, " getPriority" , GetPriority);
430458 SetMethod (
431459 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_);
433465 SetMethod (context, target, " getOSInformation" , GetOSInformation);
434466 target
435467 ->Set (context,
@@ -446,7 +478,9 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
446478 registry->Register (GetFreeMemory);
447479 registry->Register (GetCPUInfo);
448480 registry->Register (GetInterfaceAddresses);
449- registry->Register (GetOnLineStatus);
481+ registry->Register (SlowGetOnLineStatus);
482+ registry->Register (FastGetOnLineStatus);
483+ registry->Register (fast_get_on_line_status_.GetTypeInfo ());
450484 registry->Register (GetHomeDirectory);
451485 registry->Register (GetUserInfo);
452486 registry->Register (SetPriority);
0 commit comments