From d9a6b1010fa8d1d9d2fce0974b5d8e89558e150a Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 10 Feb 2019 11:28:33 +0100 Subject: [PATCH] App.listen may take host, port, callback now --- src/AppWrapper.h | 22 +++++++++++++++++++--- uWebSockets | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/AppWrapper.h b/src/AppWrapper.h index 60a34f4..f5660bf 100644 --- a/src/AppWrapper.h +++ b/src/AppWrapper.h @@ -171,13 +171,29 @@ template void uWS_App_listen(const FunctionCallbackInfo &args) { APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0); - int port = args[0]->Uint32Value(args.GetIsolate()->GetCurrentContext()).ToChecked(); + /* Invalid use */ + if (args.Length() != 2 && args.Length() != 3) { + /* Throw here */ + args.GetReturnValue().Set(isolate->ThrowException(String::NewFromUtf8(isolate, "App.listen takes 2 or 3 arguments"))); + return; + } - app->listen(port, [&args](auto *token) { + auto cb = [&args](auto *token) { /* Return a false boolean if listen failed */ Local argv[] = {token ? Local::Cast(External::New(isolate, token)) : Local::Cast(Boolean::New(isolate, false))}; Local::Cast(args[1])->Call(isolate->GetCurrentContext()->Global(), 1, argv); - }); + }; + + if (args.Length() == 2) { + /* Port, callback */ + int port = args[0]->Uint32Value(args.GetIsolate()->GetCurrentContext()).ToChecked(); + app->listen(port, std::move(cb)); + } else { + /* Host, port, callback */ + NativeString host(isolate, args[0]); + int port = args[1]->Uint32Value(args.GetIsolate()->GetCurrentContext()).ToChecked(); + app->listen(std::string(host.getString().data(), host.getString().length()), port, std::move(cb)); + } args.GetReturnValue().Set(args.Holder()); } diff --git a/uWebSockets b/uWebSockets index 399318f..02f20bf 160000 --- a/uWebSockets +++ b/uWebSockets @@ -1 +1 @@ -Subproject commit 399318f8663cb6c53471c8b7be03d230a13c7a3b +Subproject commit 02f20bf0307549cd126b582a2ad1fcf2d0180a58