Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE

What to do when GetOverlappedResult results in ERROR_IO_INCOMPLETE

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingperformancequestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code o mat
    wrote on last edited by
    #1

    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

    _ 1 Reply Last reply
    0
    • C Code o mat

      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

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      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.

      _Microsoft MVP (Visual C++) Polymorphism in C

      C 1 Reply Last reply
      0
      • _ _Superman_

        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.

        _Microsoft MVP (Visual C++) Polymorphism in C

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        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 <

        _ 1 Reply Last reply
        0
        • C Code o mat

          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 <

          _ Offline
          _ Offline
          _Superman_
          wrote on last edited by
          #4

          That's strange. Could you try giving TRUE for the third parameter of WaitForMultipleObjects or use WaitForSingleObject!!!

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++) Polymorphism in C

          C 1 Reply Last reply
          0
          • _ _Superman_

            That's strange. Could you try giving TRUE for the third parameter of WaitForMultipleObjects or use WaitForSingleObject!!!

            «_Superman_»  _I love work. It gives me something to do between weekends.

            _Microsoft MVP (Visual C++) Polymorphism in C

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #5

            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 <

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups