Strange exception throw - assign: Operation not permitted

前端 未结 4 2002
暗喜
暗喜 2020-12-03 19:18

I want to do asynchronous read from cin therefore I have a piece of code

client.h

...
boost::asio::posix::stream_descriptor input;
boost::asio::stre         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 19:58

    Can you try with this minimal reproducer? It works on my Ubuntu 64-bit box:

    #include 
    #include 
    
    #include 
    
    int main()
    {
        using namespace boost::asio;
    
        io_service io;
        posix::stream_descriptor input(io);
    
        input.assign(STDIN_FILENO);
        streambuf input_buffer;
    
        std::function loop = [&] {
            async_read_until(input, input_buffer, '\n', [&](boost::system::error_code ec, size_t) {
                if (ec) 
                    std::cerr << ec.message();
                else {
                    std::cout << "LOOP: '" << &input_buffer << "'\n";
                    loop();
                }
            });
        };
    
        loop();
        io.run();
    }
    

    Update I think I can reproduce the problem on Coliru: can you check the output of ulimit -a?

提交回复
热议问题