Skip to content

Commit 16ec524

Browse files
authored
Merge pull request #532 from Bartel-C8/v6fixElectron21
Fixes #514
2 parents 1c08cfd + 0068e0d commit 16ec524

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

binding.gyp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'zmq_no_sync_resolve%': 'false',
66
'sanitizers%': 'false',
77
'openssl_fips': '',
8+
'runtime%': 'node',
89
},
910

1011
'targets': [
@@ -51,7 +52,6 @@
5152
],
5253

5354
'defines': [
54-
'NAPI_VERSION=3',
5555
'ZMQ_STATIC',
5656
],
5757

@@ -96,6 +96,9 @@
9696
}],
9797
],
9898
}],
99+
['runtime=="electron"', {
100+
"defines": ["NODE_RUNTIME_ELECTRON=1"]
101+
}],
99102
],
100103

101104
'configurations': {

src/incoming_msg.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ IncomingMsg::~IncomingMsg() {
1414
}
1515

1616
Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
17+
#if !(NODE_RUNTIME_ELECTRON && NODE_MODULE_VERSION >= 109) // 109 is Electron v21 and up
1718
if (moved) {
1819
/* If ownership has been transferred, do not attempt to read the buffer
1920
again in any case. This should not happen of course. */
@@ -22,10 +23,12 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
2223
}
2324

2425
static auto constexpr zero_copy_threshold = 1 << 7;
26+
#endif
2527

2628
auto data = reinterpret_cast<uint8_t*>(zmq_msg_data(*ref));
2729
auto length = zmq_msg_size(*ref);
2830

31+
#if !(NODE_RUNTIME_ELECTRON && NODE_MODULE_VERSION >= 109) // 109 is Electron v21 and up
2932
if (length > zero_copy_threshold) {
3033
/* Reuse existing buffer for external storage. This avoids copying but
3134
does include an overhead in having to call a finalizer when the
@@ -43,6 +46,7 @@ Napi::Value IncomingMsg::IntoBuffer(const Napi::Env& env) {
4346

4447
return Napi::Buffer<uint8_t>::New(env, data, length, release, ref);
4548
}
49+
#endif
4650

4751
if (length > 0) {
4852
return Napi::Buffer<uint8_t>::Copy(env, data, length);

src/prefix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#pragma once
33

44
#include <napi.h>
5+
#include <node_version.h>
56
#define NAPI_BUILD_VERSION NAPI_VERSION
67

78
#include <zmq.h>

0 commit comments

Comments
 (0)