Win7 boost :: asio :: windows :: stream_handle constructor causes an error

The following code gets an error while trying to execute the last line

 boost::shared_ptr<boost::asio::io_service> ioServicePtr(new boost::asio::io_service());
 //setup the terminal with stdin and stdout

 int inFD = ::dup(STDIN_FILENO);

 int outFD = ::dup(STDOUT_FILENO);

 HANDLE osfhandle = (HANDLE)_get_osfhandle(inFD);//osfhandle is valid

 boost::asio::windows::stream_handle inputStream(*ioServicePtr, osfhandle); //error

error:

uncaught exception of type N5boost16exception_detail10clone_implINS0_19error_info_injectorINS_6system12system_errorEEEEE
- assign: The parameter is incorrect

Rate your input.

@sehe

I tried

hstdhandle = GetStdHandle(STD_OUTPUT_HANDLE);

and got the same error

So i tried

HANDLE handle= 
CreateFile(
    "CONIN$", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 
    FILE_FLAG_OVERLAPPED, NULL);
boost::asio::windows::stream_handle inputStream(*ioServicePtr, handle); 

and the mistake was

-assign handle invalid
+4
source share
1 answer

You can use GetStdHandle, therefore:

HANDLE isfhandle = GetStdHandle(STD_INPUT_HANDLE);

However, I do not think that consoles support asynchronous I / O in windows:

  • The handle must be an object that supports overlapping I / O.

    If a handle is provided, it must be open to block I / O. For example, you must specify a flag FILE_FLAG_OVERLAPPEDwhen using the CreateFile function to get a handle

    CreateFile , CreateFile .

, async IO stdin/stdout.


, Linux IO - - /: Strange exception throw - assign: Operation not

+3

All Articles