fix: close windows read handle when reading one byte (#197)

Makes sure we always close the event handle when we're done reading.

Finishes up #165
This commit is contained in:
Francis Gulotta 2024-12-23 15:12:00 -05:00 • committed by GitHub
parent f8bfc1eed2
commit 4655cc1439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -455,6 +455,7 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
}
if (!baton->bytesToRead) {
baton->complete = true;
CloseHandle(ov->hEvent);
return;
}
@ -467,6 +468,7 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
lastError = GetLastError();
ErrorCodeToString("Setting COM timeout (SetCommTimeouts)", lastError, baton->errorString);
baton->complete = true;
// CloseHandle(ov->hEvent); // wondering if we need to close the handle here
return;
}
@ -494,11 +496,11 @@ void __stdcall ReadIOCompletion(DWORD errorCode, DWORD bytesTransferred, OVERLAP
return;
}
}
CloseHandle(ov->hEvent);
baton->bytesToRead -= bytesTransferred;
baton->bytesRead += bytesTransferred;
baton->complete = true;
CloseHandle(ov->hEvent);
}
DWORD __stdcall ReadThread(LPVOID param) {