We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In function:
void HidDevice::HidDeviceReaderThread::onStartHandler() { if( this->device != NULL ) { std::string tempBuf; #ifdef OS_WINDOWS WaitForSingleObject( this->runningMutex, INFINITE); this->running = true; ReleaseMutex(this->runningMutex); DWORD bytesRead; OVERLAPPED readOL; while(this->running) { WaitForSingleObject( this->runningMutex, INFINITE); if( this->device->isInitialized() and this->device->isOpened() ) { memset(&(readOL), 0, sizeof(readOL)); readOL.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); bytesRead = 0; tempBuf = ""; tempBuf.resize(this->device->internalReadBufferSize, 0); ResetEvent(readOL.hEvent); if( !ReadFile(this->device->devHandle, &(tempBuf[0]), tempBuf.size(), &bytesRead, &readOL) ) { if (GetLastError() != ERROR_IO_PENDING) { CancelIo(this->device->devHandle); CloseHandle(readOL.hEvent); ReleaseMutex(this->runningMutex); msleep(1); continue; } } if( WaitForSingleObject(readOL.hEvent, POLLING_TIME_MS) != WAIT_OBJECT_0 ) { CancelIo(this->device->devHandle); CloseHandle(readOL.hEvent); ReleaseMutex(this->runningMutex); msleep(DEVICE_READ_INTERVAL_MS); continue; } if( GetOverlappedResult(this->device->devHandle, &readOL, &bytesRead, TRUE) ) { if( bytesRead > 0 ) this->device->readFifoBuffer.push(tempBuf); } CloseHandle(readOL.hEvent); } ReleaseMutex(this->runningMutex); msleep(DEVICE_READ_INTERVAL_MS); } #endif
Work around (works for me):
void HidDevice::HidDeviceReaderThread::onStartHandler() { if( this->device != NULL ) { std::string tempBuf; #ifdef OS_WINDOWS static bool isReadRoutineInit = false; WaitForSingleObject( this->runningMutex, INFINITE); this->running = true; ReleaseMutex(this->runningMutex); DWORD bytesRead; OVERLAPPED readOL; memset(&(readOL), 0, sizeof(readOL)); readOL.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); bytesRead = 0; tempBuf = ""; tempBuf.resize(this->device->internalReadBufferSize, 0); while(this->running) { WaitForSingleObject( this->runningMutex, INFINITE); if( this->device->isInitialized() and this->device->isOpened() ) { if(isReadRoutineInit == false) { isReadRoutineInit = true; ReadFile(this->device->devHandle, &(tempBuf[0]), tempBuf.size(), &bytesRead, &readOL); ResetEvent(readOL.hEvent); } else if (GetLastError() != ERROR_IO_PENDING) { CancelIo(this->device->devHandle); ReadFile(this->device->devHandle, &(tempBuf[0]), tempBuf.size(), &bytesRead, &readOL); ResetEvent(readOL.hEvent); } else if( !WaitForSingleObject(readOL.hEvent, POLLING_TIME_MS) != WAIT_OBJECT_0 ) { if( GetOverlappedResult(this->device->devHandle, &readOL, &bytesRead, TRUE) ) { if( bytesRead > 0 ) this->device->readFifoBuffer.push(tempBuf); CancelIo(this->device->devHandle); ReadFile(this->device->devHandle, &(tempBuf[0]), tempBuf.size(), &bytesRead, &readOL); ResetEvent(readOL.hEvent); } } } else { if(isReadRoutineInit == true) isReadRoutineInit = false; } ReleaseMutex(this->runningMutex); msleep(DEVICE_READ_INTERVAL_MS); } CloseHandle(readOL.hEvent); #endif
The text was updated successfully, but these errors were encountered:
No branches or pull requests
In function:
Data will be lost if arrive beetween CloseHandle() and ReadFile() call.
Work around (works for me):
The text was updated successfully, but these errors were encountered: