Don't keep socketPf separately
This commit is contained in:
parent
244ad00e67
commit
c6b72cf854
@ -109,10 +109,10 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
/* Retrieve temporary userData object */
|
/* Retrieve temporary userData object */
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
|
|
||||||
/* Copy entires from userData, only if we have it set */
|
/* Copy entires from userData, only if we have it set (not the case for default constructor) */
|
||||||
if (perSocketData->socketPf) {
|
if (!perSocketData->socketPf.IsEmpty()) {
|
||||||
/* socketPf points to a stack allocated UniquePersistent, or nullptr, at this point */
|
/* socketPf points to a stack allocated UniquePersistent, or nullptr, at this point */
|
||||||
Local<Object> userData = Local<Object>::New(isolate, *(perSocketData->socketPf));
|
Local<Object> userData = Local<Object>::New(isolate, perSocketData->socketPf);
|
||||||
|
|
||||||
/* Merge userData and wsObject; this code is exceedingly horrible */
|
/* Merge userData and wsObject; this code is exceedingly horrible */
|
||||||
Local<Array> keys;
|
Local<Array> keys;
|
||||||
@ -127,8 +127,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Attach a new V8 object with pointer to us, to it */
|
/* Attach a new V8 object with pointer to us, to it */
|
||||||
perSocketData->socketPf = new UniquePersistent<Object>;
|
perSocketData->socketPf.Reset(isolate, wsObject);
|
||||||
perSocketData->socketPf->Reset(isolate, wsObject);
|
|
||||||
|
|
||||||
Local<Function> openLf = Local<Function>::New(isolate, openPf);
|
Local<Function> openLf = Local<Function>::New(isolate, openPf);
|
||||||
if (!openLf->IsUndefined()) {
|
if (!openLf->IsUndefined()) {
|
||||||
@ -145,7 +144,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer::New(isolate, (void *) message.data(), message.length());
|
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer::New(isolate, (void *) message.data(), message.length());
|
||||||
|
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
Local<Value> argv[3] = {Local<Object>::New(isolate, *(perSocketData->socketPf)),
|
Local<Value> argv[3] = {Local<Object>::New(isolate, perSocketData->socketPf),
|
||||||
messageArrayBuffer,
|
messageArrayBuffer,
|
||||||
Boolean::New(isolate, opCode == uWS::OpCode::BINARY)};
|
Boolean::New(isolate, opCode == uWS::OpCode::BINARY)};
|
||||||
|
|
||||||
@ -162,7 +161,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
HandleScope hs(isolate);
|
HandleScope hs(isolate);
|
||||||
|
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
Local<Value> argv[1] = {Local<Object>::New(isolate, *(perSocketData->socketPf))
|
Local<Value> argv[1] = {Local<Object>::New(isolate, perSocketData->socketPf)
|
||||||
};
|
};
|
||||||
CallJS(isolate, Local<Function>::New(isolate, drainPf), 1, argv);
|
CallJS(isolate, Local<Function>::New(isolate, drainPf), 1, argv);
|
||||||
};
|
};
|
||||||
@ -174,7 +173,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
HandleScope hs(isolate);
|
HandleScope hs(isolate);
|
||||||
|
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
Local<Value> argv[1] = {Local<Object>::New(isolate, *(perSocketData->socketPf))};
|
Local<Value> argv[1] = {Local<Object>::New(isolate, perSocketData->socketPf)};
|
||||||
CallJS(isolate, Local<Function>::New(isolate, pingPf), 1, argv);
|
CallJS(isolate, Local<Function>::New(isolate, pingPf), 1, argv);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -185,7 +184,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
HandleScope hs(isolate);
|
HandleScope hs(isolate);
|
||||||
|
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
Local<Value> argv[1] = {Local<Object>::New(isolate, *(perSocketData->socketPf))};
|
Local<Value> argv[1] = {Local<Object>::New(isolate, perSocketData->socketPf)};
|
||||||
CallJS(isolate, Local<Function>::New(isolate, pongPf), 1, argv);
|
CallJS(isolate, Local<Function>::New(isolate, pongPf), 1, argv);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -196,7 +195,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
|
|
||||||
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer::New(isolate, (void *) message.data(), message.length());
|
Local<ArrayBuffer> messageArrayBuffer = ArrayBuffer::New(isolate, (void *) message.data(), message.length());
|
||||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||||
Local<Object> wsObject = Local<Object>::New(isolate, *(perSocketData->socketPf));
|
Local<Object> wsObject = Local<Object>::New(isolate, perSocketData->socketPf);
|
||||||
|
|
||||||
/* Invalidate this wsObject */
|
/* Invalidate this wsObject */
|
||||||
wsObject->SetAlignedPointerInInternalField(0, nullptr);
|
wsObject->SetAlignedPointerInInternalField(0, nullptr);
|
||||||
@ -208,7 +207,8 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
CallJS(isolate, closeLf, 3, argv);
|
CallJS(isolate, closeLf, 3, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete perSocketData->socketPf;
|
/* This should technically not be required */
|
||||||
|
perSocketData->socketPf.Reset();
|
||||||
|
|
||||||
/* Again, here we clear the buffer to avoid strange bugs */
|
/* Again, here we clear the buffer to avoid strange bugs */
|
||||||
NeuterArrayBuffer(messageArrayBuffer);
|
NeuterArrayBuffer(messageArrayBuffer);
|
||||||
|
@ -323,7 +323,7 @@ struct HttpResponseWrapper {
|
|||||||
|
|
||||||
/* Immediately calls open handler */
|
/* Immediately calls open handler */
|
||||||
res->template upgrade<PerSocketData>({
|
res->template upgrade<PerSocketData>({
|
||||||
&userData
|
std::move(userData)
|
||||||
}, secWebSocketKey.getString(), secWebSocketProtocol.getString(),
|
}, secWebSocketKey.getString(), secWebSocketProtocol.getString(),
|
||||||
secWebSocketExtensions.getString(), context);
|
secWebSocketExtensions.getString(), context);
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Va
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct PerSocketData {
|
struct PerSocketData {
|
||||||
UniquePersistent<Object> *socketPf = nullptr;
|
UniquePersistent<Object> socketPf;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PerContextData {
|
struct PerContextData {
|
||||||
|
@ -137,8 +137,6 @@ void Main(Local<Object> exports) {
|
|||||||
exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "DEDICATED_COMPRESSOR_128KB", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::DEDICATED_COMPRESSOR_128KB)).ToChecked();
|
exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "DEDICATED_COMPRESSOR_128KB", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::DEDICATED_COMPRESSOR_128KB)).ToChecked();
|
||||||
exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "DEDICATED_COMPRESSOR_256KB", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::DEDICATED_COMPRESSOR_256KB)).ToChecked();
|
exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "DEDICATED_COMPRESSOR_256KB", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, uWS::DEDICATED_COMPRESSOR_256KB)).ToChecked();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Listen options */
|
/* Listen options */
|
||||||
exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "LIBUS_LISTEN_EXCLUSIVE_PORT", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, LIBUS_LISTEN_EXCLUSIVE_PORT)).ToChecked();
|
exports->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "LIBUS_LISTEN_EXCLUSIVE_PORT", NewStringType::kNormal).ToLocalChecked(), Integer::NewFromUnsigned(isolate, LIBUS_LISTEN_EXCLUSIVE_PORT)).ToChecked();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user