Port to Nodejs 17
This commit is contained in:
parent
4b30a36b6c
commit
c680b1297b
8
build.c
8
build.c
@ -33,10 +33,10 @@ struct node_version {
|
|||||||
char *name;
|
char *name;
|
||||||
char *abi;
|
char *abi;
|
||||||
} versions[] = {
|
} versions[] = {
|
||||||
{"v12.13.0", "72"},
|
|
||||||
{"v14.0.0", "83"},
|
{"v14.0.0", "83"},
|
||||||
{"v15.0.0", "88"},
|
{"v15.0.0", "88"},
|
||||||
{"v16.0.0", "93"}
|
{"v16.0.0", "93"},
|
||||||
|
{"v17.0.1", "102"}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Downloads headers, creates folders */
|
/* Downloads headers, creates folders */
|
||||||
@ -55,8 +55,8 @@ void prepare() {
|
|||||||
|
|
||||||
/* Build for Unix systems */
|
/* Build for Unix systems */
|
||||||
void build(char *compiler, char *cpp_compiler, char *cpp_linker, char *os, char *arch) {
|
void build(char *compiler, char *cpp_compiler, char *cpp_linker, char *os, char *arch) {
|
||||||
char *c_shared = "-DLIBUS_USE_LIBUV -DLIBUS_USE_OPENSSL -flto -O3 -c -fPIC -I uWebSockets/uSockets/src uWebSockets/uSockets/src/*.c uWebSockets/uSockets/src/eventing/*.c uWebSockets/uSockets/src/crypto/*.c";
|
char *c_shared = "-DOPENSSL_CONFIGURED_API=0x10100000L -DOPENSSL_API_COMPAT=0x10100000L -DLIBUS_USE_LIBUV -DLIBUS_USE_OPENSSL -flto -O3 -c -fPIC -I uWebSockets/uSockets/src uWebSockets/uSockets/src/*.c uWebSockets/uSockets/src/eventing/*.c uWebSockets/uSockets/src/crypto/*.c";
|
||||||
char *cpp_shared = "-DUWS_WITH_PROXY -DLIBUS_USE_LIBUV -DLIBUS_USE_OPENSSL -flto -O3 -c -fPIC -std=c++17 -I uWebSockets/uSockets/src -I uWebSockets/src src/addon.cpp uWebSockets/uSockets/src/crypto/sni_tree.cpp";
|
char *cpp_shared = "-DOPENSSL_CONFIGURED_API=0x10100000L -DOPENSSL_API_COMPAT=0x10100000L -DUWS_WITH_PROXY -DLIBUS_USE_LIBUV -DLIBUS_USE_OPENSSL -flto -O3 -c -fPIC -std=c++17 -I uWebSockets/uSockets/src -I uWebSockets/src src/addon.cpp uWebSockets/uSockets/src/crypto/sni_tree.cpp";
|
||||||
|
|
||||||
for (unsigned int i = 0; i < sizeof(versions) / sizeof(struct node_version); i++) {
|
for (unsigned int i = 0; i < sizeof(versions) / sizeof(struct node_version); i++) {
|
||||||
run("%s %s -I targets/node-%s/include/node", compiler, c_shared, versions[i].name);
|
run("%s %s -I targets/node-%s/include/node", compiler, c_shared, versions[i].name);
|
||||||
|
@ -169,7 +169,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
behavior.message = [messagePf = std::move(messagePf), isolate](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
behavior.message = [messagePf = std::move(messagePf), isolate](auto *ws, std::string_view message, uWS::OpCode opCode) {
|
||||||
HandleScope hs(isolate);
|
HandleScope hs(isolate);
|
||||||
|
|
||||||
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),
|
||||||
@ -221,7 +221,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||||||
behavior.close = [closePf = std::move(closePf), isolate](auto *ws, int code, std::string_view message) {
|
behavior.close = [closePf = std::move(closePf), isolate](auto *ws, int code, std::string_view message) {
|
||||||
HandleScope hs(isolate);
|
HandleScope hs(isolate);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ struct HttpResponseWrapper {
|
|||||||
res->onData([p = std::move(p), isolate](std::string_view data, bool last) {
|
res->onData([p = std::move(p), isolate](std::string_view data, bool last) {
|
||||||
HandleScope hs(isolate);
|
HandleScope hs(isolate);
|
||||||
|
|
||||||
Local<ArrayBuffer> dataArrayBuffer = ArrayBuffer::New(isolate, (void *) data.data(), data.length());
|
Local<ArrayBuffer> dataArrayBuffer = ArrayBuffer_New(isolate, (void *) data.data(), data.length());
|
||||||
|
|
||||||
Local<Value> argv[] = {dataArrayBuffer, Boolean::New(isolate, last)};
|
Local<Value> argv[] = {dataArrayBuffer, Boolean::New(isolate, last)};
|
||||||
CallJS(isolate, Local<Function>::New(isolate, p), 2, argv);
|
CallJS(isolate, Local<Function>::New(isolate, p), 2, argv);
|
||||||
@ -107,7 +107,7 @@ struct HttpResponseWrapper {
|
|||||||
std::string_view ip = res->getRemoteAddress();
|
std::string_view ip = res->getRemoteAddress();
|
||||||
|
|
||||||
/* Todo: we need to pass a copy here */
|
/* Todo: we need to pass a copy here */
|
||||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ struct HttpResponseWrapper {
|
|||||||
std::string_view ip = res->getRemoteAddressAsText();
|
std::string_view ip = res->getRemoteAddressAsText();
|
||||||
|
|
||||||
/* Todo: we need to pass a copy here */
|
/* Todo: we need to pass a copy here */
|
||||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ struct HttpResponseWrapper {
|
|||||||
std::string_view ip = res->getProxiedRemoteAddress();
|
std::string_view ip = res->getProxiedRemoteAddress();
|
||||||
|
|
||||||
/* Todo: we need to pass a copy here */
|
/* Todo: we need to pass a copy here */
|
||||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ struct HttpResponseWrapper {
|
|||||||
std::string_view ip = res->getProxiedRemoteAddressAsText();
|
std::string_view ip = res->getProxiedRemoteAddressAsText();
|
||||||
|
|
||||||
/* Todo: we need to pass a copy here */
|
/* Todo: we need to pass a copy here */
|
||||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@ MaybeLocal<Value> CallJS(Isolate *isolate, Local<Function> f, int argc, Local<Va
|
|||||||
return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0});
|
return node::MakeCallback(isolate, isolate->GetCurrentContext()->Global(), f, argc, argv, {0, 0});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Local<v8::ArrayBuffer> ArrayBuffer_New(Isolate *isolate, void *data, size_t length) {
|
||||||
|
std::unique_ptr<BackingStore> backingStore = ArrayBuffer::NewBackingStore(data, length, [](void* data, size_t length, void* deleter_data) {}, nullptr);
|
||||||
|
return ArrayBuffer::New(isolate, std::shared_ptr<BackingStore>(backingStore.release()));
|
||||||
|
}
|
||||||
|
|
||||||
struct PerSocketData {
|
struct PerSocketData {
|
||||||
UniquePersistent<Object> socketPf;
|
UniquePersistent<Object> socketPf;
|
||||||
};
|
};
|
||||||
@ -103,19 +108,19 @@ public:
|
|||||||
length = utf8Value->length();
|
length = utf8Value->length();
|
||||||
} else if (value->IsTypedArray()) {
|
} else if (value->IsTypedArray()) {
|
||||||
Local<ArrayBufferView> arrayBufferView = Local<ArrayBufferView>::Cast(value);
|
Local<ArrayBufferView> arrayBufferView = Local<ArrayBufferView>::Cast(value);
|
||||||
ArrayBuffer::Contents contents = arrayBufferView->Buffer()->GetContents();
|
auto contents = arrayBufferView->Buffer()->GetBackingStore();
|
||||||
length = arrayBufferView->ByteLength();
|
length = arrayBufferView->ByteLength();
|
||||||
data = (char *) contents.Data() + arrayBufferView->ByteOffset();
|
data = (char *) contents->Data() + arrayBufferView->ByteOffset();
|
||||||
} else if (value->IsArrayBuffer()) {
|
} else if (value->IsArrayBuffer()) {
|
||||||
Local<ArrayBuffer> arrayBuffer = Local<ArrayBuffer>::Cast(value);
|
Local<ArrayBuffer> arrayBuffer = Local<ArrayBuffer>::Cast(value);
|
||||||
ArrayBuffer::Contents contents = arrayBuffer->GetContents();
|
auto contents = arrayBuffer->GetBackingStore();
|
||||||
length = contents.ByteLength();
|
length = contents->ByteLength();
|
||||||
data = (char *) contents.Data();
|
data = (char *) contents->Data();
|
||||||
} else if (value->IsSharedArrayBuffer()) {
|
} else if (value->IsSharedArrayBuffer()) {
|
||||||
Local<SharedArrayBuffer> arrayBuffer = Local<SharedArrayBuffer>::Cast(value);
|
Local<SharedArrayBuffer> arrayBuffer = Local<SharedArrayBuffer>::Cast(value);
|
||||||
SharedArrayBuffer::Contents contents = arrayBuffer->GetContents();
|
auto contents = arrayBuffer->GetBackingStore();
|
||||||
length = contents.ByteLength();
|
length = contents->ByteLength();
|
||||||
data = (char *) contents.Data();
|
data = (char *) contents->Data();
|
||||||
} else {
|
} else {
|
||||||
invalid = true;
|
invalid = true;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ struct WebSocketWrapper {
|
|||||||
std::string_view ip = ws->getRemoteAddress();
|
std::string_view ip = ws->getRemoteAddress();
|
||||||
|
|
||||||
/* Todo: we need to pass a copy here */
|
/* Todo: we need to pass a copy here */
|
||||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +150,7 @@ struct WebSocketWrapper {
|
|||||||
std::string_view ip = ws->getRemoteAddressAsText();
|
std::string_view ip = ws->getRemoteAddressAsText();
|
||||||
|
|
||||||
/* Todo: we need to pass a copy here */
|
/* Todo: we need to pass a copy here */
|
||||||
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
args.GetReturnValue().Set(ArrayBuffer_New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ void uWS_getParts(const FunctionCallbackInfo<Value> &args) {
|
|||||||
|
|
||||||
std::string_view part = optionalPart.value();
|
std::string_view part = optionalPart.value();
|
||||||
|
|
||||||
Local<ArrayBuffer> partArrayBuffer = ArrayBuffer::New(isolate, (void *) part.data(), part.length());
|
Local<ArrayBuffer> partArrayBuffer = ArrayBuffer_New(isolate, (void *) part.data(), part.length());
|
||||||
/* Map is 30% faster in this case, but a static Object could be faster still */
|
/* Map is 30% faster in this case, but a static Object could be faster still */
|
||||||
Local<Object> partMap = Object::New(isolate);
|
Local<Object> partMap = Object::New(isolate);
|
||||||
partMap->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "data", NewStringType::kNormal).ToLocalChecked(), partArrayBuffer).IsNothing();
|
partMap->Set(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "data", NewStringType::kNormal).ToLocalChecked(), partArrayBuffer).IsNothing();
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 02691e0cde03e72f9d670e0398be756ac97073e2
|
Subproject commit 5d8983902690a0b93193d922d6239965bdca2f76
|
Loading…
Reference in New Issue
Block a user