
I have the following simplified code to read data from a RS232 port. For some (from beginning) runs, io.run() returns immediately and m_handler() is called which is expected. but sometimes (a fresh run from beginning), io.run() goes into a inside forever loop(stacked inside forever) even for the first time called inside the while loop. And this happens randomly. What's is/are the potential problem(s) at here? Thanks. -shunguang #define BUF_SIZE 512 char data[BUF_SIZE]; void my_handler(const boost::system::error_code& err, std::size_t bytes_transferred) { printf("%d\n", bytes_transferred); if (!err){ process_data(); } } void test_serial_port( int argc, char* argv[] ) { // hard coded parameters const char *PORT = "COM1"; serial_port_base::baud_rate BAUD(9600); serial_port_base::character_size CSIZE( 8 ); serial_port_base::flow_control FLOW( serial_port_base::flow_control::software ); serial_port_base::parity PARITY( serial_port_base::parity::none ); serial_port_base::stop_bits STOP( serial_port_base::stop_bits::one ); io_service io; serial_port port( io, PORT ); // go through and set all the options as we need them // all of them are listed, but the default values work for most cases port.set_option( BAUD ); port.set_option( CSIZE ); port.set_option( FLOW ); port.set_option( PARITY ); port.set_option( STOP ); while( !kbhit() ) { io.reset(); port.async_read_some( boost::asio::buffer(data, BUF_SIZE), boost::bind(&my_handler, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred ) ); io.run(); Sleep(300); } } -- View this message in context: http://boost.2283326.n4.nabble.com/boost-io-service-run-never-returns-tp4649... Sent from the Boost - Users mailing list archive at Nabble.com.