class pending_guard
{
- bool& b_;
+ bool* b_ = nullptr;
bool clear_ = true;
public:
~pending_guard()
{
- if(clear_)
- b_ = false;
+ if(clear_ && b_)
+ *b_ = false;
+ }
+
+ pending_guard()
+ : b_(nullptr)
+ , clear_(true)
+ {
}
explicit
pending_guard(bool& b)
- : b_(b)
+ : b_(&b)
{
// If this assert goes off, it means you are attempting
// to issue two of the same asynchronous I/O operation
// calls to async_read_some. Only one pending call of
// each I/O type (read and write) is permitted.
//
- BOOST_ASSERT(! b_);
- b_ = true;
+ BOOST_ASSERT(! *b_);
+ *b_ = true;
}
pending_guard(
{
}
+ void assign(bool& b)
+ {
+ BOOST_ASSERT(!b_);
+ BOOST_ASSERT(clear_);
+ b_ = &b;
+
+ // If this assert goes off, it means you are attempting
+ // to issue two of the same asynchronous I/O operation
+ // at the same time, without waiting for the first one
+ // to complete. For example, attempting two simultaneous
+ // calls to async_read_some. Only one pending call of
+ // each I/O type (read and write) is permitted.
+ //
+ BOOST_ASSERT(! *b_);
+ *b_ = true;
+ }
+
void
reset()
{
BOOST_ASSERT(clear_);
- b_ = false;
+ if (b_)
+ *b_ = false;
clear_ = false;
}
};