boost::io_service run() never returns sometimes -
i have following code read data rs232 port. (from beginning) runs, io.run()
returns , m_handler()
called expected. (a fresh run beginning), io.run()
goes inside forever loop(stacked inside forever) first time called inside while loop. , happens randomly. what's is/are potential problem(s) @ here?
#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 , set options need them // of them listed, default values work 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); } }
Comments
Post a Comment