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. Is it impossible to use IOCP for consoles ?

Is it impossible to use IOCP for consoles ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 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.
  • I Offline
    I Offline
    iir
    wrote on last edited by
    #1

    In the following short program, CreateIoCompletionPort fails and GetLastError says invalid handle was supplied. Return values from CreateFile is not INVALID_HANDLE_VALUE so I guess that IOCP doesn't accept handles for consoles. I just want to confirm that it is true or I made a mistake in this program. I intended to receive console inputs via IOCP. #include #include int main( void ) { HANDLE stdin_handle, iocp, stdout_handle; stdin_handle = CreateFile( "CON", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL ); stdout_handle = CreateFile( "CON", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL ); iocp = CreateIoCompletionPort( stdin_handle, NULL, 0, 1 ); if( iocp ) { CloseHandle( iocp ); puts( "O.K." ); } else { printf( "Error = %lu, stdin=%p, stdout=%p invalid_handle=%p\n", GetLastError(), stdin_handle, stdout_handle, INVALID_HANDLE_VALUE ); } return 0; } -- modified at 4:02 Tuesday 10th January, 2006

    _ 1 Reply Last reply
    0
    • I iir

      In the following short program, CreateIoCompletionPort fails and GetLastError says invalid handle was supplied. Return values from CreateFile is not INVALID_HANDLE_VALUE so I guess that IOCP doesn't accept handles for consoles. I just want to confirm that it is true or I made a mistake in this program. I intended to receive console inputs via IOCP. #include #include int main( void ) { HANDLE stdin_handle, iocp, stdout_handle; stdin_handle = CreateFile( "CON", GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL ); stdout_handle = CreateFile( "CON", GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL ); iocp = CreateIoCompletionPort( stdin_handle, NULL, 0, 1 ); if( iocp ) { CloseHandle( iocp ); puts( "O.K." ); } else { printf( "Error = %lu, stdin=%p, stdout=%p invalid_handle=%p\n", GetLastError(), stdin_handle, stdout_handle, INVALID_HANDLE_VALUE ); } return 0; } -- modified at 4:02 Tuesday 10th January, 2006

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

      the completion key should not be 0. besides, i always create a iocp with no handle, and then attach stuff to it.

      I 1 Reply Last reply
      0
      • _ __yb

        the completion key should not be 0. besides, i always create a iocp with no handle, and then attach stuff to it.

        I Offline
        I Offline
        iir
        wrote on last edited by
        #3

        Though I supply non-zero value for the completion key ( the 3rd arg. ), the result is the same. And I couldn't find restrictions for the value of the completion key mentioned in MSDN. And supplying INVALID_HANDLE_VALUE for the 1st arg is not compatible for NT 3.5 or below.

        _ 1 Reply Last reply
        0
        • I iir

          Though I supply non-zero value for the completion key ( the 3rd arg. ), the result is the same. And I couldn't find restrictions for the value of the completion key mentioned in MSDN. And supplying INVALID_HANDLE_VALUE for the 1st arg is not compatible for NT 3.5 or below.

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

          so maybe instead of CreateFile(CON) u acquire the handle u want from GetStdHandle ?

          I 1 Reply Last reply
          0
          • _ __yb

            so maybe instead of CreateFile(CON) u acquire the handle u want from GetStdHandle ?

            I Offline
            I Offline
            iir
            wrote on last edited by
            #5

            At the first time I tried to use GetStdHandle but IOCP was not created. So I tried to use CreateFile to supply FILE_FLAG_OVERLAPPED for the console handle. Finally I concluded that IOCP cannot be used for console I/O.

            _ 1 Reply Last reply
            0
            • I iir

              At the first time I tried to use GetStdHandle but IOCP was not created. So I tried to use CreateFile to supply FILE_FLAG_OVERLAPPED for the console handle. Finally I concluded that IOCP cannot be used for console I/O.

              _ Offline
              _ Offline
              __yb
              wrote on last edited by
              #6

              Oops.. You are right! The documentation for CreateFile says that the dwFlagsAndAttributes argument is ignored on console objects.

              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