Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60705 - in trunk: boost/asio/detail libs/asio/test/ip
From: chris_at_[hidden]
Date: 2010-03-19 09:08:05


Author: chris_kohlhoff
Date: 2010-03-19 09:08:04 EDT (Fri, 19 Mar 2010)
New Revision: 60705
URL: http://svn.boost.org/trac/boost/changeset/60705

Log:
Fix epoll_reactor bug where cancelled operations would complete with a
"success" error_code.

Text files modified:
   trunk/boost/asio/detail/epoll_reactor.hpp | 18 ++++++++++++++++--
   trunk/libs/asio/test/ip/tcp.cpp | 30 ++++++++++++++++++++++++++++--
   2 files changed, 44 insertions(+), 4 deletions(-)

Modified: trunk/boost/asio/detail/epoll_reactor.hpp
==============================================================================
--- trunk/boost/asio/detail/epoll_reactor.hpp (original)
+++ trunk/boost/asio/detail/epoll_reactor.hpp 2010-03-19 09:08:04 EDT (Fri, 19 Mar 2010)
@@ -212,7 +212,14 @@
 
     op_queue<operation> ops;
     for (int i = 0; i < max_ops; ++i)
- ops.push(descriptor_data->op_queue_[i]);
+ {
+ while (reactor_op* op = descriptor_data->op_queue_[i].front())
+ {
+ op->ec_ = boost::asio::error::operation_aborted;
+ descriptor_data->op_queue_[i].pop();
+ ops.push(op);
+ }
+ }
 
     descriptor_lock.unlock();
 
@@ -233,7 +240,14 @@
 
     op_queue<operation> ops;
     for (int i = 0; i < max_ops; ++i)
- ops.push(descriptor_data->op_queue_[i]);
+ {
+ while (reactor_op* op = descriptor_data->op_queue_[i].front())
+ {
+ op->ec_ = boost::asio::error::operation_aborted;
+ descriptor_data->op_queue_[i].pop();
+ ops.push(op);
+ }
+ }
 
     descriptor_lock.unlock();
 

Modified: trunk/libs/asio/test/ip/tcp.cpp
==============================================================================
--- trunk/libs/asio/test/ip/tcp.cpp (original)
+++ trunk/libs/asio/test/ip/tcp.cpp 2010-03-19 09:08:04 EDT (Fri, 19 Mar 2010)
@@ -344,6 +344,14 @@
   BOOST_CHECK(bytes_transferred == sizeof(write_data));
 }
 
+void handle_read_cancel(const boost::system::error_code& err,
+ size_t bytes_transferred, bool* called)
+{
+ *called = true;
+ BOOST_CHECK(err == boost::asio::error::operation_aborted);
+ BOOST_CHECK(bytes_transferred == 0);
+}
+
 void handle_read_eof(const boost::system::error_code& err,
     size_t bytes_transferred, bool* called)
 {
@@ -422,6 +430,26 @@
   BOOST_CHECK(write_completed);
   BOOST_CHECK(memcmp(read_buffer, write_data, sizeof(write_data)) == 0);
 
+ // Cancelled read.
+
+ bool read_cancel_completed = false;
+ boost::asio::async_read(server_side_socket,
+ boost::asio::buffer(read_buffer),
+ boost::bind(handle_read_cancel,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred,
+ &read_cancel_completed));
+
+ ios.reset();
+ ios.poll();
+ BOOST_CHECK(!read_cancel_completed);
+
+ server_side_socket.close();
+
+ ios.reset();
+ ios.run();
+ BOOST_CHECK(read_cancel_completed);
+
   // A read when the peer closes socket should fail with eof.
 
   bool read_eof_completed = false;
@@ -432,8 +460,6 @@
         boost::asio::placeholders::bytes_transferred,
         &read_eof_completed));
 
- server_side_socket.close();
-
   ios.reset();
   ios.run();
   BOOST_CHECK(read_eof_completed);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk