boost::asio 1.43 regression (canceling read operation doens't trigger operation_aborted)

Hello, I had working 1.42 code that suddenly stopped working with 1.43. With a bit of investigation I found out that canceling an async_read operation on a serial port when a timer was fired didn't trigger the expected boost::asio::error::operation_aborted like it used to do. Here is a testcase: http://codepad.org/XnLwybDl The idea is to implement a "read with timeout" functionality on a serial port. Btw, is this the correct way to implement this? Is there a simpler way to read from a serial port with a timeout? Thanks, Philippe

I forgot to add some details: - it works fine when there's data to read (I can cancel the timer just fine) - it fails when the timer fire and I try to cancel the read operation on the serial port - this happens on Windows XP with msvc++ 2008 express edition Thanks! :) Philippe

Hi Philippe, unfortunately that's one major painpoint with asio and will remain to be one: https://svn.boost.org/trac/boost/ticket/2832 HTH, Stephan On Thu, Jun 10, 2010 at 1:52 PM, Philippe Vaucher <philippe.vaucher@gmail.com> wrote:
Hello,
I had working 1.42 code that suddenly stopped working with 1.43. With a bit of investigation I found out that canceling an async_read operation on a serial port when a timer was fired didn't trigger the expected boost::asio::error::operation_aborted like it used to do.
Here is a testcase: http://codepad.org/XnLwybDl
The idea is to implement a "read with timeout" functionality on a serial port. Btw, is this the correct way to implement this? Is there a simpler way to read from a serial port with a timeout?
Thanks, Philippe _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

unfortunately that's one major painpoint with asio and will remain to be one: https://svn.boost.org/trac/boost/ticket/2832
Well, that's for synchronous reads. My example is with an asynchronous read, and it used to work before. Cleary it's a regression unless I'm missing something. Philippe

I actually found out the problem. It seems 1.43 introduced BOOST_ASIO_ENABLE_CANCELIO. When I define this, everything works again. Now there's still a bug! When trying to call cancel() on a serial_port when BOOST_ASIO_ENABLE_CANCELIO is not defined, it should fail with asio::error::operation_not_supported as the doc says, but it doens't. It just silently tries to go on with reading from the serial port. Philippe

Now there's still a bug! When trying to call cancel() on a serial_port when BOOST_ASIO_ENABLE_CANCELIO is not defined, it should fail with asio::error::operation_not_supported as the doc says, but it doens't. It just silently tries to go on with reading from the serial port.
The problem is that when BOOST_ASIO_ENABLE_CANCELIO is not defined, asio\detail\win_iocp_handle_service.hpp makes it so impl.safe_cancellation_thread_id_ is equal to 0 and then when cancelling the following code is executed: else if (impl.safe_cancellation_thread_id_ == 0) { // No operations have been started, so there's nothing to cancel. ec = boost::system::error_code(); } Thus cancel() thinks there's nothing to cancel, and asio::error::operation_not_supported isn't triggered. Philippe
participants (2)
-
Philippe Vaucher
-
Stephan Menzel