#pragma once #include "mplexer.hh" #include "tcpiohandler.hh" #if 0 #define DEBUGLOG_ENABLED #define DEBUGLOG(x) cerr< ttd) { DEBUGLOG("in "<<__PRETTY_FUNCTION__<<" for fd "< ttd = boost::none) { DEBUGLOG("in "<<__PRETTY_FUNCTION__<<" for fd "<& handler): d_handler(handler), d_enabled(true) { } ~IOStateGuard() { /* if we are still owning the state when we go out of scope, let's reset the state so it's not registered to the IO multiplexer anymore and its reference count goes to zero */ if (d_enabled && d_handler) { DEBUGLOG("IOStateGuard destroyed while holding a state, let's reset it"); try { d_handler->reset(); } catch (const FDMultiplexerException& e) { /* that should not happen, but an exception raised from a destructor would be bad so better safe than sorry */ } d_enabled = false; } } void release() { d_enabled = false; } private: std::unique_ptr& d_handler; bool d_enabled; };