مكالمات لإرجاع readfile error_working_set_quota
-
27-09-2019 - |
سؤال
يعمل البرنامج بشكل جيد لبضع دقائق ، ثم يبدأ القراءة في الفشل باستخدام رمز الخطأ error_working_set_quota.
أنا أستخدم Readfile مع I/O متداخلة مثل ذلك:
while (continueReading)
{
BOOL bSuccess = ReadFile(deviceHandle, pReadBuf, length,
&bytesRead, readOverlappedPtr);
waitVal = WaitForMultipleObjects(
(sizeof(eventsToWaitFor)/sizeof(eventsToWaitFor[0])),
eventsToWaitFor, FALSE, INFINITE);
if (waitVal == WAIT_OBJECT_0) {
// do stuff
} else if (waitVal == WAIT_OBJECT_0 + 1) {
// do stuff
} else if (waitVal == WAIT_OBJECT_0 + 2) {
// complete the read
bSuccess = GetOverlappedResult(deviceHandle, &readOverlapped,
&bytesRead, FALSE);
if (!bSuccess) {
errorCode = GetLastError();
printf("ReadFile error=%d\n", errorCode);
}
}
}
لماذا أحصل على هذا الخطأ؟
المحلول
المشكلة هي أن القراءة يتم استدعاؤها مرات أكثر من getOverloppedResult. مما تسبب في نفاد العملية من الموارد للتعامل مع جميع القراءات المعلقة.
بالإضافة إلى ذلك ، يجب أن نتحقق من نتيجة Readfile والتأكد من أن النتيجة هي error_io_pending ، إذا لم يكن ذلك وإرجاع القراءة ، فهناك مشكلة أخرى.
تأكد من استدعاء getOverloppedResult مرة واحدة لكل مكالمة إلى Readfile. مثل ذلك:
BOOL bPerformRead = TRUE;
while (continueReading)
{
BOOL bSuccess = TRUE;
// only perform the read if the last one has finished
if (bPerformRead) {
bSuccess = ReadFile(deviceHandle, pReadBuf, length,
&bytesRead, readOverlappedPtr);
if (!bSuccess) {
errorCode = GetLastError();
if (errorCode != ERROR_IO_PENDING) {
printf("ReadFile error=%d\n", errorCode);
return;
}
} else {
// read completed right away
continue;
}
// we can't perform another read until this one finishes
bPerformRead = FALSE;
}
waitVal = WaitForMultipleObjects(
(sizeof(eventsToWaitFor)/sizeof(eventsToWaitFor[0])),
eventsToWaitFor, FALSE, INFINITE);
if (waitVal == WAIT_OBJECT_0) {
// do stuff
} else if (waitVal == WAIT_OBJECT_0 + 1) {
// do stuff
} else if (waitVal == WAIT_OBJECT_0 + 2) {
// complete the read
bSuccess = GetOverlappedResult(deviceHandle, &readOverlapped,
&bytesRead, FALSE);
// the read is finished, we can read again
bPerformRead = TRUE;
if (!bSuccess) {
errorCode = GetLastError();
printf("GetOverlappedResult from ReadFile error=%d\n", errorCode);
}
}
}
لا تنتمي إلى StackOverflow