@jason2866/serialport-bindings-cpp 13.0.0 → 13.0.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jason2866/serialport-bindings-cpp",
3
3
  "description": "SerialPort Hardware bindings for node serialport written in c++",
4
- "version": "13.0.0",
4
+ "version": "13.0.2",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "keywords": [
@@ -327,28 +327,12 @@ bool IsClosingHandle(int fd) {
327
327
  void __stdcall WriteIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAPPED* ov) {
328
328
  WriteBaton* baton = static_cast<WriteBaton*>(ov->hEvent);
329
329
  DWORD bytesWritten;
330
-
331
- if (errorCode) {
332
- ErrorCodeToString("Writing to COM port (WriteIOCompletion)", errorCode, baton->errorString);
333
- baton->complete = true;
334
- return;
335
- }
336
-
337
- // hEvent holds a user pointer (baton), not a valid event handle.
338
- // GetOverlappedResult with bWait=TRUE would call WaitForSingleObject
339
- // on hEvent if Internal is still STATUS_PENDING, which fails with
340
- // ERROR_INVALID_HANDLE. Temporarily clear it so the function falls
341
- // back to the file-handle signalling path.
342
- HANDLE savedEvent = ov->hEvent;
343
- ov->hEvent = NULL;
344
330
  if (!GetOverlappedResult(int2handle(baton->fd), ov, &bytesWritten, TRUE)) {
345
- ov->hEvent = savedEvent;
346
331
  errorCode = GetLastError();
347
332
  ErrorCodeToString("Writing to COM port (GetOverlappedResult)", errorCode, baton->errorString);
348
333
  baton->complete = true;
349
334
  return;
350
335
  }
351
- ov->hEvent = savedEvent;
352
336
  if (bytesWritten) {
353
337
  baton->offset += bytesWritten;
354
338
  if (baton->offset >= baton->bufferLength) {
@@ -457,22 +441,15 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
457
441
  return;
458
442
  }
459
443
 
444
+ // bytesTransferred is already provided by the APC completion callback.
445
+ // Do NOT call GetOverlappedResult here — MSDN explicitly states:
446
+ // "Do not use GetOverlappedResult for I/O operations that use
447
+ // ReadFileEx or WriteFileEx completion routines."
448
+ // The overlapped's hEvent holds a ReadBaton pointer (not a Windows event
449
+ // handle), so GetOverlappedResult fails with ERROR_INVALID_HANDLE on
450
+ // drivers that inspect hEvent (e.g. usbser.sys used by ESP32 native USB).
451
+
460
452
  DWORD lastError;
461
- // hEvent holds a user pointer (baton), not a valid event handle.
462
- // GetOverlappedResult with bWait=TRUE would call WaitForSingleObject
463
- // on hEvent if Internal is still STATUS_PENDING, which fails with
464
- // ERROR_INVALID_HANDLE. Temporarily clear it so the function falls
465
- // back to the file-handle signalling path.
466
- HANDLE savedEvent = ov->hEvent;
467
- ov->hEvent = NULL;
468
- if (!GetOverlappedResult(int2handle(baton->fd), ov, &bytesTransferred, TRUE)) {
469
- ov->hEvent = savedEvent;
470
- lastError = GetLastError();
471
- ErrorCodeToString("Reading from COM port (GetOverlappedResult)", lastError, baton->errorString);
472
- baton->complete = true;
473
- return;
474
- }
475
- ov->hEvent = savedEvent;
476
453
  if (bytesTransferred) {
477
454
  baton->bytesToRead -= bytesTransferred;
478
455
  baton->bytesRead += bytesTransferred;
@@ -480,7 +457,7 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
480
457
  }
481
458
  if (!baton->bytesToRead) {
482
459
  baton->complete = true;
483
- CloseHandle(ov->hEvent);
460
+ // Note: ov->hEvent is a baton pointer, not a Windows handle — do not CloseHandle
484
461
  return;
485
462
  }
486
463
 
@@ -918,15 +895,9 @@ void ListBaton::Execute() {
918
895
  }
919
896
  if (isCom) {
920
897
  ListResultItem* resultItem = new ListResultItem();
921
- if (name) {
922
- resultItem->path = name;
923
- }
924
- if (manufacturer) {
925
- resultItem->manufacturer = manufacturer;
926
- }
927
- if (pnpId) {
928
- resultItem->pnpId = pnpId;
929
- }
898
+ resultItem->path = name;
899
+ resultItem->manufacturer = manufacturer;
900
+ resultItem->pnpId = pnpId;
930
901
  if (vendorId) {
931
902
  resultItem->vendorId = vendorId;
932
903
  }
@@ -949,9 +920,7 @@ void ListBaton::Execute() {
949
920
  free(manufacturer);
950
921
  free(name);
951
922
 
952
- if (hkey != INVALID_HANDLE_VALUE) {
953
- RegCloseKey(hkey);
954
- }
923
+ RegCloseKey(hkey);
955
924
  memberIndex++;
956
925
  }
957
926
  if (hDevInfo) {