Commit c9c996b4 authored by Alex Hultman's avatar Alex Hultman
Browse files

Introduce setNoop, MakeCallback(noop) in uv_check_t

parent 3671984c
#include "../src/uWS.h"
#include "addon.h"
uv_prepare_t prepare;
void Main(Local<Object> exports) {
Isolate *isolate = exports->GetIsolate();
......@@ -17,11 +15,8 @@ void Main(Local<Object> exports) {
NODE_SET_METHOD(exports, "transfer", transfer);
NODE_SET_METHOD(exports, "upgrade", upgrade);
NODE_SET_METHOD(exports, "connect", connect);
uv_prepare_init(hub.getLoop(), &prepare);
uv_prepare_start(&prepare, [](uv_prepare_t *prepare) {
makeCallbackSkipCount = 0;
});
NODE_SET_METHOD(exports, "setNoop", setNoop);
registerCheck(isolate);
}
NODE_MODULE(uws, Main)
......@@ -9,8 +9,19 @@ using namespace std;
using namespace v8;
uWS::Hub hub(0, true);
const int MAKE_CALLBACK_SKIP_MAX = 100;
int makeCallbackSkipCount = 0;
uv_check_t check;
Persistent<Function> noop;
void registerCheck(Isolate *isolate) {
uv_check_init(hub.getLoop(), &check);
check.data = isolate;
uv_check_start(&check, [](uv_check_t *check) {
Isolate *isolate = (Isolate *) check->data;
HandleScope hs(isolate);
node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), Local<Function>::New(isolate, noop), 0, nullptr);
});
uv_unref((uv_handle_t *) &check);
}
class NativeString {
char *data;
......@@ -267,13 +278,7 @@ void onMessage(const FunctionCallbackInfo<Value> &args) {
HandleScope hs(isolate);
Local<Value> argv[] = {wrapMessage(message, length, opCode, isolate),
getDataV8(webSocket, isolate)};
if (!makeCallbackSkipCount) {
node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), Local<Function>::New(isolate, *messageCallback), 2, argv);
makeCallbackSkipCount = MAKE_CALLBACK_SKIP_MAX - 1;
} else {
Local<Function>::New(isolate, *messageCallback)->Call(isolate->GetCurrentContext()->Global(), 2, argv);
makeCallbackSkipCount--;
}
Local<Function>::New(isolate, *messageCallback)->Call(isolate->GetCurrentContext()->Global(), 2, argv);
});
}
......@@ -421,6 +426,10 @@ void startAutoPing(const FunctionCallbackInfo<Value> &args) {
group->startAutoPing(args[1]->IntegerValue(), std::string(nativeString.getData(), nativeString.getLength()));
}
void setNoop(const FunctionCallbackInfo<Value> &args) {
noop.Reset(args.GetIsolate(), Local<Function>::Cast(args[0]));
}
template <bool isServer>
struct Namespace {
Local<Object> object;
......
......@@ -34,6 +34,8 @@ const native = (() => {
}
})();
native.setNoop(noop);
var _upgradeReq = null;
const clientGroup = native.client.group.create();
native.client.group.onConnection(clientGroup, (external) => {
......
......@@ -3,8 +3,6 @@
#include "../env.h"
#include "../env-inl.h"
uv_prepare_t prepare;
namespace node {
void Main(Local<Object> exports, Local<Value> unused, Local<Context> context) {
......@@ -22,11 +20,8 @@ void Main(Local<Object> exports, Local<Value> unused, Local<Context> context) {
env->SetMethod(exports, "transfer", transfer);
env->SetMethod(exports, "upgrade", upgrade);
env->SetMethod(exports, "connect", connect);
uv_prepare_init(hub.getLoop(), &prepare);
uv_prepare_start(&prepare, [](uv_prepare_t *prepare) {
makeCallbackSkipCount = 0;
});
env->SetMethod(exports, "setNoop", setNoop);
registerCheck(isolate);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment