Is it impossible to use IOCP for consoles ?
-
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
-
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
-
the completion key should not be 0. besides, i always create a iocp with no handle, and then attach stuff to it.
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.
-
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.
-
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.