usb 2.4.0 → 2.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/binding.gyp +1 -0
- package/dist/usb/endpoint.d.ts +1 -1
- package/dist/usb/endpoint.js +4 -2
- package/dist/usb/endpoint.js.map +1 -1
- package/package.json +2 -2
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +3 -3
- package/src/node_usb.cc +2 -0
- package/src/thread_name.cc +79 -0
- package/src/thread_name.h +11 -0
- package/tsc/usb/endpoint.ts +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.4.3] - 2022-06-21
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Fixed poll transfer tracking - [`522`](https://github.com/node-usb/node-usb/pull/522) ([Rob Moran](https://github.com/thegecko))
|
|
7
|
+
|
|
8
|
+
## [2.4.2] - 2022-05-27
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fixed multiple events with device detection on Windows - [`512`](https://github.com/node-usb/node-usb/pull/512) ([Alba Mendez](https://github.com/mildsunrise))
|
|
12
|
+
|
|
13
|
+
## [2.4.1] - 2022-05-07
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Fixed node engine ranges in package.json - ([Rob Moran](https://github.com/thegecko))
|
|
17
|
+
|
|
3
18
|
## [2.4.0] - 2022-05-02
|
|
4
19
|
|
|
5
20
|
### Fixed
|
package/binding.gyp
CHANGED
package/dist/usb/endpoint.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare abstract class Endpoint extends EventEmitter {
|
|
|
32
32
|
export declare class InEndpoint extends Endpoint {
|
|
33
33
|
/** Endpoint direction. */
|
|
34
34
|
direction: 'in' | 'out';
|
|
35
|
-
protected pollTransfers: Transfer[]
|
|
35
|
+
protected pollTransfers: Transfer[];
|
|
36
36
|
protected pollTransferSize: number;
|
|
37
37
|
protected pollPending: number;
|
|
38
38
|
pollActive: boolean;
|
package/dist/usb/endpoint.js
CHANGED
|
@@ -58,6 +58,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
58
58
|
var _this = _super.call(this, device, descriptor) || this;
|
|
59
59
|
/** Endpoint direction. */
|
|
60
60
|
_this.direction = 'in';
|
|
61
|
+
_this.pollTransfers = [];
|
|
61
62
|
_this.pollTransferSize = 0;
|
|
62
63
|
_this.pollPending = 0;
|
|
63
64
|
_this.pollActive = false;
|
|
@@ -115,6 +116,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
115
116
|
_this.pollPending--;
|
|
116
117
|
if (_this.pollPending === 0) {
|
|
117
118
|
_this.pollTransfers = [];
|
|
119
|
+
_this.pollActive = false;
|
|
118
120
|
_this.emit('end');
|
|
119
121
|
}
|
|
120
122
|
}
|
|
@@ -140,7 +142,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
140
142
|
InEndpoint.prototype.startPollTransfers = function (nTransfers, transferSize, callback) {
|
|
141
143
|
if (nTransfers === void 0) { nTransfers = 3; }
|
|
142
144
|
if (transferSize === void 0) { transferSize = this.descriptor.wMaxPacketSize; }
|
|
143
|
-
if (this.
|
|
145
|
+
if (this.pollActive) {
|
|
144
146
|
throw new Error('Polling already active');
|
|
145
147
|
}
|
|
146
148
|
this.pollTransferSize = transferSize;
|
|
@@ -162,7 +164,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
162
164
|
* @param callback
|
|
163
165
|
*/
|
|
164
166
|
InEndpoint.prototype.stopPoll = function (callback) {
|
|
165
|
-
if (!this.
|
|
167
|
+
if (!this.pollActive) {
|
|
166
168
|
throw new Error('Polling is not active.');
|
|
167
169
|
}
|
|
168
170
|
for (var i = 0; i < this.pollTransfers.length; i++) {
|
package/dist/usb/endpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../tsc/usb/endpoint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAsC;AACtC,uCAA0F;AAG1F,IAAM,QAAQ,GAAG,UAAC,GAAyB,IAAwB,OAAA,GAAG,IAAI,GAAG,YAAY,UAAU,EAAhC,CAAgC,CAAC;AAEpG,kDAAkD;AAClD;IAAuC,4BAAY;IAe/C,kBAAsB,MAAc,EAAE,UAA8B;QAApE,YACI,iBAAO,SAIV;QALqB,YAAM,GAAN,MAAM,CAAQ;QANpC,8GAA8G;QACvG,aAAO,GAAG,CAAC,CAAC;QAOf,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,KAAI,CAAC,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC;QAC3C,KAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC;;IACvD,CAAC;IAED,wDAAwD;IACjD,4BAAS,GAAhB,UAAiB,QAAsD;QACnE,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;OAQG;IACI,+BAAY,GAAnB,UAAoB,OAAe,EAAE,QAA4F;QAC7H,OAAO,IAAI,mBAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,C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MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,KAAK,CAAC,EAAE;YACtD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C;aAAM;YACH,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;SACnC;IACL,CAAC;IACL,kBAAC;AAAD,CAAC,AA9CD,CAAiC,QAAQ,GA8CxC;AA9CY,kCAAW"}
|
package/package.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"name": "usb",
|
|
3
3
|
"description": "Library to access USB devices",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "2.4.
|
|
5
|
+
"version": "2.4.3",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=10.20.0 <11.x
|
|
8
|
+
"node": ">=10.20.0 <11.x || >=12.17.0 <13.0 || >=14.0.0"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/src/device.cc
CHANGED
|
@@ -14,7 +14,7 @@ Device::Device(const Napi::CallbackInfo& info) : Napi::ObjectWrap<Device>(info),
|
|
|
14
14
|
device = info[0].As<Napi::External<libusb_device>>().Data();
|
|
15
15
|
libusb_ref_device(device);
|
|
16
16
|
|
|
17
|
-
std::map<libusb_device*, Device
|
|
17
|
+
std::map<libusb_device*, Device*>& byPtr = env.GetInstanceData<ModuleData>()->byPtr;
|
|
18
18
|
byPtr[device] = this;
|
|
19
19
|
|
|
20
20
|
DEBUG_LOG("Created device %p", this);
|
|
@@ -25,7 +25,7 @@ Device::~Device() {
|
|
|
25
25
|
DEBUG_LOG("Freed device %p", this);
|
|
26
26
|
|
|
27
27
|
ModuleData* instanceData = env.GetInstanceData<ModuleData>();
|
|
28
|
-
std::map<libusb_device*, Device
|
|
28
|
+
std::map<libusb_device*, Device*>& byPtr = instanceData->byPtr;
|
|
29
29
|
|
|
30
30
|
auto it = byPtr.find(device);
|
|
31
31
|
if (it != byPtr.end() && it->second == this)
|
|
@@ -38,7 +38,7 @@ Device::~Device() {
|
|
|
38
38
|
// or create a new one and add it to the map.
|
|
39
39
|
Napi::Object Device::get(Napi::Env env, libusb_device* dev) {
|
|
40
40
|
ModuleData* instanceData = env.GetInstanceData<ModuleData>();
|
|
41
|
-
std::map<libusb_device*, Device
|
|
41
|
+
std::map<libusb_device*, Device*>& byPtr = instanceData->byPtr;
|
|
42
42
|
|
|
43
43
|
auto it = byPtr.find(dev);
|
|
44
44
|
if (it != byPtr.end()) {
|
package/src/node_usb.cc
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include "node_usb.h"
|
|
2
|
+
#include "thread_name.h"
|
|
2
3
|
|
|
3
4
|
Napi::Value SetDebugLevel(const Napi::CallbackInfo& info);
|
|
4
5
|
Napi::Value UseUsbDkBackend(const Napi::CallbackInfo& info);
|
|
@@ -42,6 +43,7 @@ void handleHotplug(HotPlug* info){
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
void USBThreadFn(ModuleData* instanceData) {
|
|
46
|
+
SetThreadName("node-usb events");
|
|
45
47
|
libusb_context* usb_context = instanceData->usb_context;
|
|
46
48
|
|
|
47
49
|
while(true) {
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Definition of a SetThreadName function with an emphasis in "portability",
|
|
2
|
+
// meaning we prefer cautiously failing over creating build errors (or crashes)
|
|
3
|
+
// on exotic platforms. To do this, we only include/link against very
|
|
4
|
+
// few & widely available symbols.
|
|
5
|
+
#include "thread_name.h"
|
|
6
|
+
|
|
7
|
+
#if defined(__linux__)
|
|
8
|
+
|
|
9
|
+
// For Linux use the prctl API directly. prctl symbol
|
|
10
|
+
// should be available under any libc.
|
|
11
|
+
#include <sys/prctl.h>
|
|
12
|
+
|
|
13
|
+
// Define here to avoid relying on kernel headers being present
|
|
14
|
+
#define PR_SET_NAME 15 /* Set process name */
|
|
15
|
+
|
|
16
|
+
bool SetThreadName(const char* name) {
|
|
17
|
+
return prctl(PR_SET_NAME, name, 0, 0, 0) >= 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#elif defined(__APPLE__)
|
|
21
|
+
|
|
22
|
+
// For MacOS use the dynamic linker because I don't
|
|
23
|
+
// want to take any risks
|
|
24
|
+
#include <dlfcn.h>
|
|
25
|
+
|
|
26
|
+
extern "C" typedef int (*SetNameFn)(const char*);
|
|
27
|
+
|
|
28
|
+
bool SetThreadName(const char* name) {
|
|
29
|
+
auto pthread_setname_np = reinterpret_cast<SetNameFn>(
|
|
30
|
+
dlsym(RTLD_DEFAULT, "pthread_setname_np"));
|
|
31
|
+
if (pthread_setname_np == nullptr)
|
|
32
|
+
return false;
|
|
33
|
+
return pthread_setname_np(name) == 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#elif defined(_WIN32)
|
|
37
|
+
|
|
38
|
+
// For Windows, we use the new SetThreadDescription API which
|
|
39
|
+
// is only available in newish versions. To avoid taking any
|
|
40
|
+
// risks (and because on certain versions it's the only
|
|
41
|
+
// option to access the API), we use the dynamic linker
|
|
42
|
+
#include <windows.h>
|
|
43
|
+
|
|
44
|
+
extern "C" typedef HRESULT (WINAPI *SetThreadDescriptionFn)(HANDLE, PCWSTR);
|
|
45
|
+
|
|
46
|
+
static SetThreadDescriptionFn RetrieveSymbol(const char* objectName) {
|
|
47
|
+
auto mod = GetModuleHandleA(objectName);
|
|
48
|
+
if (mod == nullptr) return nullptr;
|
|
49
|
+
auto symbol = GetProcAddress(mod, "SetThreadDescription");
|
|
50
|
+
return reinterpret_cast<SetThreadDescriptionFn>(symbol);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#include <locale>
|
|
54
|
+
#include <codecvt>
|
|
55
|
+
#include <string>
|
|
56
|
+
|
|
57
|
+
bool SetThreadName(const char* name) {
|
|
58
|
+
auto SetThreadDescription = RetrieveSymbol("Kernel32.dll");
|
|
59
|
+
// apparently, MSDN is wrong and the symbol is defined in
|
|
60
|
+
// KernelBase.dll, so try that too
|
|
61
|
+
if (SetThreadDescription == nullptr)
|
|
62
|
+
SetThreadDescription = RetrieveSymbol("KernelBase.dll");
|
|
63
|
+
|
|
64
|
+
if (SetThreadDescription == nullptr) return false;
|
|
65
|
+
|
|
66
|
+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
|
67
|
+
std::wstring wide_name = converter.from_bytes(name);
|
|
68
|
+
|
|
69
|
+
auto result = SetThreadDescription(GetCurrentThread(), wide_name.c_str());
|
|
70
|
+
return SUCCEEDED(result);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#else
|
|
74
|
+
|
|
75
|
+
bool SetThreadName(const char* name) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#endif
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets the name of the calling thread to `name`, which is
|
|
3
|
+
* a NUL terminated UTF-8 string. Returns true if success,
|
|
4
|
+
* false if error or unsupported platform.
|
|
5
|
+
*
|
|
6
|
+
* Since this is an OS-dependent operation, the requirements
|
|
7
|
+
* of `name` may vary depending on platform. For example on
|
|
8
|
+
* Linux, the maximum length (excluding the terminator) is
|
|
9
|
+
* 16 bytes, and UTF-8 isn't strictly required (only conventional).
|
|
10
|
+
*/
|
|
11
|
+
bool SetThreadName(const char* name);
|
package/tsc/usb/endpoint.ts
CHANGED
|
@@ -52,7 +52,7 @@ export class InEndpoint extends Endpoint {
|
|
|
52
52
|
/** Endpoint direction. */
|
|
53
53
|
public direction: 'in' | 'out' = 'in';
|
|
54
54
|
|
|
55
|
-
protected pollTransfers: Transfer[]
|
|
55
|
+
protected pollTransfers: Transfer[] = [];
|
|
56
56
|
protected pollTransferSize = 0;
|
|
57
57
|
protected pollPending = 0;
|
|
58
58
|
public pollActive = false;
|
|
@@ -113,6 +113,7 @@ export class InEndpoint extends Endpoint {
|
|
|
113
113
|
|
|
114
114
|
if (this.pollPending === 0) {
|
|
115
115
|
this.pollTransfers = [];
|
|
116
|
+
this.pollActive = false;
|
|
116
117
|
this.emit('end');
|
|
117
118
|
}
|
|
118
119
|
}
|
|
@@ -138,7 +139,7 @@ export class InEndpoint extends Endpoint {
|
|
|
138
139
|
}
|
|
139
140
|
|
|
140
141
|
protected startPollTransfers(nTransfers = 3, transferSize = this.descriptor.wMaxPacketSize, callback: (error: LibUSBException | undefined, buffer: Buffer, actualLength: number) => void): Transfer[] {
|
|
141
|
-
if (this.
|
|
142
|
+
if (this.pollActive) {
|
|
142
143
|
throw new Error('Polling already active');
|
|
143
144
|
}
|
|
144
145
|
|
|
@@ -163,7 +164,7 @@ export class InEndpoint extends Endpoint {
|
|
|
163
164
|
* @param callback
|
|
164
165
|
*/
|
|
165
166
|
public stopPoll(callback?: () => void): void {
|
|
166
|
-
if (!this.
|
|
167
|
+
if (!this.pollActive) {
|
|
167
168
|
throw new Error('Polling is not active.');
|
|
168
169
|
}
|
|
169
170
|
for (let i = 0; i < this.pollTransfers.length; i++) {
|