Boost.Asio iostream flush not working?

any ideas why stream.flush(); will not work?

 boost::asio::ip::tcp::iostream stream("localhost","5000"); assert(stream.good()); stream << 1; stream.flush(); while(true); 

it is cleared only if the loop is deleted and the line is boost::this_thread::sleep(boost::posix_time::seconds(1));
(much later).

thanks

Update: I did some more debugging, and the problem is not really a flush command. If I let my code connect to the netcat server, everything will be fine. I assume that the problem is that both the client and the server are in the same process (I create two threats, one of which acts as a server as a client). When I put them in separate processes, everything works fine, but when both are in the same process, the transfer stops until sleep is called ... (this is only for testing reasons, later both will work on different servers).

The platform is WindowsXP.

Any ideas why this is happening?

0
source share
1 answer

How do you know that flash does not work? I suspect that your time (true) is very heavy on your system. This may interfere with the work of the recipient.

Try using the same code with the recipient on a different host for verification.

Update: I think the problem is that it is empty (true); I would use something like:

 while(true) { sleep(1); } 

or a nanolayer defined in the ctime header. Finally, yes, I believe that a working server and client in the same process will cause you more problems.

/ Tobias

+1
source

All Articles