|
Boost-Commit : |
From: chris_at_[hidden]
Date: 2007-10-20 21:48:04
Author: chris_kohlhoff
Date: 2007-10-20 21:48:03 EDT (Sat, 20 Oct 2007)
New Revision: 40241
URL: http://svn.boost.org/trac/boost/changeset/40241
Log:
Ensure the buffers and completion condition objects are destroyed before
the completion handler is invoked.
Text files modified:
trunk/boost/asio/impl/read.ipp | 20 ++++++++++++--------
trunk/boost/asio/impl/write.ipp | 18 ++++++++++++------
2 files changed, 24 insertions(+), 14 deletions(-)
Modified: trunk/boost/asio/impl/read.ipp
==============================================================================
--- trunk/boost/asio/impl/read.ipp (original)
+++ trunk/boost/asio/impl/read.ipp 2007-10-20 21:48:03 EDT (Sat, 20 Oct 2007)
@@ -19,6 +19,7 @@
#include <boost/asio/detail/push_options.hpp>
#include <algorithm>
+#include <boost/optional.hpp>
#include <boost/asio/detail/pop_options.hpp>
#include <boost/asio/buffer.hpp>
@@ -139,23 +140,25 @@
std::size_t bytes_transferred)
{
total_transferred_ += bytes_transferred;
- buffers_.consume(bytes_transferred);
- if (completion_condition_(ec, total_transferred_)
- || buffers_.begin() == buffers_.end())
+ buffers_->consume(bytes_transferred);
+ if ((*completion_condition_)(ec, total_transferred_)
+ || buffers_->begin() == buffers_->end())
{
+ buffers_.reset();
+ completion_condition_.reset();
handler_(ec, total_transferred_);
}
else
{
- stream_.async_read_some(buffers_, *this);
+ stream_.async_read_some(*buffers_, *this);
}
}
//private:
AsyncReadStream& stream_;
- buffers_type buffers_;
+ boost::optional<buffers_type> buffers_;
std::size_t total_transferred_;
- CompletionCondition completion_condition_;
+ boost::optional<CompletionCondition> completion_condition_;
ReadHandler handler_;
};
@@ -236,8 +239,9 @@
total_transferred_ += bytes_transferred;
streambuf_.commit(bytes_transferred);
if (streambuf_.size() == streambuf_.max_size()
- || completion_condition_(ec, total_transferred_))
+ || (*completion_condition_)(ec, total_transferred_))
{
+ completion_condition_.reset();
handler_(ec, total_transferred_);
}
else
@@ -252,7 +256,7 @@
AsyncReadStream& stream_;
boost::asio::basic_streambuf<Allocator>& streambuf_;
std::size_t total_transferred_;
- CompletionCondition completion_condition_;
+ boost::optional<CompletionCondition> completion_condition_;
ReadHandler handler_;
};
Modified: trunk/boost/asio/impl/write.ipp
==============================================================================
--- trunk/boost/asio/impl/write.ipp (original)
+++ trunk/boost/asio/impl/write.ipp 2007-10-20 21:48:03 EDT (Sat, 20 Oct 2007)
@@ -17,6 +17,10 @@
#include <boost/asio/detail/push_options.hpp>
+#include <boost/asio/detail/push_options.hpp>
+#include <boost/optional.hpp>
+#include <boost/asio/detail/pop_options.hpp>
+
#include <boost/asio/buffer.hpp>
#include <boost/asio/completion_condition.hpp>
#include <boost/asio/detail/bind_handler.hpp>
@@ -125,23 +129,25 @@
std::size_t bytes_transferred)
{
total_transferred_ += bytes_transferred;
- buffers_.consume(bytes_transferred);
- if (completion_condition_(ec, total_transferred_)
- || buffers_.begin() == buffers_.end())
+ buffers_->consume(bytes_transferred);
+ if ((*completion_condition_)(ec, total_transferred_)
+ || buffers_->begin() == buffers_->end())
{
+ buffers_.reset();
+ completion_condition_.reset();
handler_(ec, total_transferred_);
}
else
{
- stream_.async_write_some(buffers_, *this);
+ stream_.async_write_some(*buffers_, *this);
}
}
//private:
AsyncWriteStream& stream_;
- buffers_type buffers_;
+ boost::optional<buffers_type> buffers_;
std::size_t total_transferred_;
- CompletionCondition completion_condition_;
+ boost::optional<CompletionCondition> completion_condition_;
WriteHandler handler_;
};
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