diff --git a/src/session.cc b/src/session.cc index 60efa64..21798d0 100644 --- a/src/session.cc +++ b/src/session.cc @@ -78,14 +78,17 @@ void session::update_all(int elapsed_time) session::~session() { logger::debug() << "session::~session() this=" << logger::format("%x", this); + + if (_wired == true) { + for (std::list >::iterator it = _ifaces.begin(); + it != _ifaces.end(); it++) { + handle_auto_unwire((*it)); + } + } for (std::list >::iterator it = _ifaces.begin(); it != _ifaces.end(); it++) { - if (_autowire == true) { - handle_auto_unwire((*it)); - } - (*it)->remove_session(_ptr); } } @@ -95,14 +98,15 @@ ptr session::create(const ptr& pr, const address& saddr, { ptr se(new session()); - se->_ptr = se; - se->_pr = pr; - se->_saddr = address("::") == saddr ? all_nodes : saddr; - se->_taddr = taddr; - se->_daddr = daddr; - se->_autowire = auto_wire; - se->_ttl = pr->timeout(); - se->_touched = true; + se->_ptr = se; + se->_pr = pr; + se->_saddr = address("::") == saddr ? all_nodes : saddr; + se->_taddr = taddr; + se->_daddr = daddr; + se->_autowire = auto_wire; + se->_wired = false; + se->_ttl = pr->timeout(); + se->_touched = true; _sessions.push_back(se); @@ -161,6 +165,8 @@ void session::handle_auto_wire(const ptr& ifa) << "session::system(" << route_cmd.str() << ")"; system(route_cmd.str().c_str()); + + _wired = true; } void session::handle_auto_unwire(const ptr& ifa) @@ -181,6 +187,8 @@ void session::handle_auto_unwire(const ptr& ifa) << "session::system(" << route_cmd.str() << ")"; system(route_cmd.str().c_str()); + + _wired = false; } void session::handle_advert(const ptr& ifa) @@ -223,6 +231,11 @@ bool session::autowire() const return _autowire; } +bool session::wired() const +{ + return _wired; +} + bool session::touched() const { return _touched; diff --git a/src/session.h b/src/session.h index b01d6c5..eacead3 100644 --- a/src/session.h +++ b/src/session.h @@ -34,6 +34,8 @@ private: bool _autowire; + bool _wired; + bool _touched; // An array of interfaces this session is monitoring for @@ -75,6 +77,8 @@ public: bool autowire() const; + bool wired() const; + bool touched() const; int status() const;