Skip to content

Commit

Permalink
More checks in Connection class
Browse files Browse the repository at this point in the history
  • Loading branch information
dkargin committed Nov 30, 2024
1 parent aa0f0a0 commit a901533
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions include/miniros/internal/observer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MINIROS_OBSERVER_H
#define MINIROS_OBSERVER_H

#include <cassert>
#include <type_traits> // for std::is_base_of

namespace miniros {
Expand Down Expand Up @@ -98,6 +99,15 @@ class Iterator {
return *m_obj;
}

operator bool () const {
return m_obj != nullptr;
}

ConnectionImpl* operator -> () {
assert(m_obj);
return m_obj;
}

protected:
ConnectionImpl* m_obj;
};
Expand Down
5 changes: 3 additions & 2 deletions src/transport/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,9 @@ void Connection::drop(DropReason reason)
std::scoped_lock<DropWatchers> lock(drop_watchers_);
for (auto it = drop_watchers_.begin(); it != drop_watchers_.end(); it++)
{
DropWatcher& watcher = *it;
watcher.onConnectionDropped(shared_from_this(), reason);
if (!it)
continue;
it->onConnectionDropped(shared_from_this(), reason);
}
}
transport_->close();
Expand Down

0 comments on commit a901533

Please sign in to comment.