Boost logo

Boost :

Subject: [boost] Problem with ASIO
From: Juan Dent (juandent_at_[hidden])
Date: 2016-02-09 20:27:56


Hi,

I have a problem with the following sample (ASIO 10, part of Boost examples):

void f() {
         {
                io_service ioservice;
        
                posix::stream_descriptor stream{ioservice, STDOUT_FILENO};
                auto handler = [](const boost::system::error_code&, std::size_t) {
                            std::cout << ", world!\n";
                };
                async_write(stream, buffer("Hello"), handler);
        
                ioservice.run();
        
                std::cout << "hhh\n";
         }
                // in this line and afterwards, no output will be seen through std::out!! ( it is somehow damaged or destroyed by the destructor of the *stream* object!!
            std::cout << “This will not print\n";

}

As explained in the line comment, when stream is destroyed some permanent damage is done to the std::out object which will not output any more after executing the code in the nested block.

I believe the stream should be somehow disconnected from STDOUT_FILENO before its destruction so it does not “harm” std::out.

Any ideas?

Thanks!!
Juan


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk