What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE
-
Hello people! I have the following (simplified) code:
OVERLAPPED Overlap = {0};
Overlap.hEvent = event_reader_with_CreateEvent;
if (ReadFile(handle_for_com_port, pBuffer, buffer_size, &bytes_read, &Overlap)) ...data read, go on happily...
else if (GetLastError() == ERROR_IO_PENDING)
{
if (WaitForMultipleObjects(1, &Overlap.hEvent, FALSE, dwTimeOut) == WAIT_OBJECT_0)
{
if (GetOverlappedResult(handle_for_com_port, &Overlap, &bytes_read, FALSE)) ...data read, go on happily ...
else if (GetLastError() == ERROR_IO_INCOMPLETE)
{
What to do here???
} else ...IO error, report and go on not so happily...
}
}So what to do in case of ERROR_IO_INCOMPLETE? Googling around i found code sniplts where they simply try GetOverlappedResult again and again for a while until it succeeds OR some timeout or somesuch occurs. However, time to time i run into the following confusing situation: 1. ReadFile called resulting in ERROR_IO_PENDING 2. Waiting on the event returns with WAIT_OBJECT_0, the event is signalled 3. GetOverlappedResult returns FALSE and the last error code is ERROR_IO_INCOMPLETE, however, if i check the buffer (pBuffer) with the debugger i see that the data is already fully in it, however, bytes_read is 0 and it remains zero and repeatedly calling GetOverlappedResult will always result in ERROR_IO_INCOMPLETE for all ethernity (or at least as long as i was willing to wait). Anyone knows why this is happening and what i can do to solve it? Another thing that turned up is that if i try to "timeout" from this, i mean, call GetOverlappedResult a few times giving up after a while and continuing will result in "damaged memory block", maybe because the buffer pointed at pBuffer goes out of scope but someone, somewhere still tries to write into it (just a guess)? Anyways, timeouting still can't be a solution because i lose the data that was actually read into the buffer, confusing confusing confusing...help!!! p.s: if i call GetOverlappedResult with TRUE as the last parameter than it just seem to hang...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <
modified on Monday, November 8, 2010 3:13 PM
-
Hello people! I have the following (simplified) code:
OVERLAPPED Overlap = {0};
Overlap.hEvent = event_reader_with_CreateEvent;
if (ReadFile(handle_for_com_port, pBuffer, buffer_size, &bytes_read, &Overlap)) ...data read, go on happily...
else if (GetLastError() == ERROR_IO_PENDING)
{
if (WaitForMultipleObjects(1, &Overlap.hEvent, FALSE, dwTimeOut) == WAIT_OBJECT_0)
{
if (GetOverlappedResult(handle_for_com_port, &Overlap, &bytes_read, FALSE)) ...data read, go on happily ...
else if (GetLastError() == ERROR_IO_INCOMPLETE)
{
What to do here???
} else ...IO error, report and go on not so happily...
}
}So what to do in case of ERROR_IO_INCOMPLETE? Googling around i found code sniplts where they simply try GetOverlappedResult again and again for a while until it succeeds OR some timeout or somesuch occurs. However, time to time i run into the following confusing situation: 1. ReadFile called resulting in ERROR_IO_PENDING 2. Waiting on the event returns with WAIT_OBJECT_0, the event is signalled 3. GetOverlappedResult returns FALSE and the last error code is ERROR_IO_INCOMPLETE, however, if i check the buffer (pBuffer) with the debugger i see that the data is already fully in it, however, bytes_read is 0 and it remains zero and repeatedly calling GetOverlappedResult will always result in ERROR_IO_INCOMPLETE for all ethernity (or at least as long as i was willing to wait). Anyone knows why this is happening and what i can do to solve it? Another thing that turned up is that if i try to "timeout" from this, i mean, call GetOverlappedResult a few times giving up after a while and continuing will result in "damaged memory block", maybe because the buffer pointed at pBuffer goes out of scope but someone, somewhere still tries to write into it (just a guess)? Anyways, timeouting still can't be a solution because i lose the data that was actually read into the buffer, confusing confusing confusing...help!!! p.s: if i call GetOverlappedResult with TRUE as the last parameter than it just seem to hang...
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <
modified on Monday, November 8, 2010 3:13 PM
I guess it is because you have not done any configuration for your serial port. This article should help you out - Serial Communication in Windows[^]
«_Superman_» _I love work. It gives me something to do between weekends.
-
I guess it is because you have not done any configuration for your serial port. This article should help you out - Serial Communication in Windows[^]
«_Superman_» _I love work. It gives me something to do between weekends.
Thank you for the link but i did set up the port using the DCB structure, SetCommState and SetCommTimeouts.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <
-
Thank you for the link but i did set up the port using the DCB structure, SetCommState and SetCommTimeouts.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <
That's strange. Could you try giving
TRUE
for the third parameter ofWaitForMultipleObjects
or useWaitForSingleObject
!!!«_Superman_» _I love work. It gives me something to do between weekends.
-
That's strange. Could you try giving
TRUE
for the third parameter ofWaitForMultipleObjects
or useWaitForSingleObject
!!!«_Superman_» _I love work. It gives me something to do between weekends.
In the actual code there are more then one event i am waiting for that is why you see
WaitForMultipleObjects
, i just simplified the code for simplicity. And yes, i am sure that the event signalling the overlapped operation completion is fired, it is the very first event handle inside the array passed to the wait function and i get WAIT_OBJECT_0 from it. Most of the time this seems to be working ok but time to time...> The problem with computers is that they do what you tell them to do and not what you want them to do. < > Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world. Fry: But this is HDTV. It's got better resolution than the real world <