mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
Allow disconnections to be signaled by drivers
This allows for disconnections to be detected quickly where possible. It also makes sure other driver errors aren't thrown in the event of a disconnection.
This commit is contained in:
committed by
Paul Hollinsky
parent
dfe2d23d85
commit
a5b27a15b0
@@ -346,7 +346,7 @@ void VCP::readTask() {
|
||||
IOTaskState state = LAUNCH;
|
||||
DWORD bytesRead = 0;
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
while(!closing) {
|
||||
while(!closing && !isDisconnected()) {
|
||||
switch(state) {
|
||||
case LAUNCH: {
|
||||
COMSTAT comStatus;
|
||||
@@ -365,8 +365,15 @@ void VCP::readTask() {
|
||||
auto lastError = GetLastError();
|
||||
if(lastError == ERROR_IO_PENDING)
|
||||
state = WAIT;
|
||||
else if(lastError != ERROR_SUCCESS)
|
||||
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
||||
else if(lastError != ERROR_SUCCESS) {
|
||||
if(lastError == ERROR_ACCESS_DENIED) {
|
||||
if(!isDisconnected()) {
|
||||
disconnected = true;
|
||||
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
||||
}
|
||||
} else
|
||||
report(APIEvent::Type::FailedToRead, APIEvent::Severity::Error);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WAIT: {
|
||||
@@ -392,7 +399,7 @@ void VCP::writeTask() {
|
||||
VCP::WriteOperation writeOp;
|
||||
DWORD bytesWritten = 0;
|
||||
EventManager::GetInstance().downgradeErrorsOnCurrentThread();
|
||||
while(!closing) {
|
||||
while(!closing && !isDisconnected()) {
|
||||
switch(state) {
|
||||
case LAUNCH: {
|
||||
if(!writeQueue.wait_dequeue_timed(writeOp, std::chrono::milliseconds(100)))
|
||||
@@ -406,7 +413,12 @@ void VCP::writeTask() {
|
||||
if(winerr == ERROR_IO_PENDING) {
|
||||
state = WAIT;
|
||||
}
|
||||
else
|
||||
else if(winerr == ERROR_ACCESS_DENIED) {
|
||||
if(!isDisconnected()) {
|
||||
disconnected = true;
|
||||
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
|
||||
}
|
||||
} else
|
||||
report(APIEvent::Type::FailedToWrite, APIEvent::Severity::Error);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user