allow for a clean shutdown of asio connections
remove heartbeat timer on close make sure only weak references are stored in bindings even below C++17
This commit is contained in:
parent
f1c32242f7
commit
cf7d2e49ff
|
|
@ -36,9 +36,9 @@
|
||||||
|
|
||||||
// C++17 has 'weak_from_this()' support.
|
// C++17 has 'weak_from_this()' support.
|
||||||
#if __cplusplus >= 201701L
|
#if __cplusplus >= 201701L
|
||||||
#define PTR_FROM_THIS weak_from_this
|
#define PTR_FROM_THIS(T) weak_from_this()
|
||||||
#else
|
#else
|
||||||
#define PTR_FROM_THIS shared_from_this
|
#define PTR_FROM_THIS(T) std::weak_ptr<T>(shared_from_this())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -142,7 +142,7 @@ protected:
|
||||||
this,
|
this,
|
||||||
_1,
|
_1,
|
||||||
_2,
|
_2,
|
||||||
PTR_FROM_THIS(),
|
PTR_FROM_THIS(Watcher),
|
||||||
connection,
|
connection,
|
||||||
fd);
|
fd);
|
||||||
return get_dispatch_wrapper(fn);
|
return get_dispatch_wrapper(fn);
|
||||||
|
|
@ -160,7 +160,7 @@ protected:
|
||||||
this,
|
this,
|
||||||
_1,
|
_1,
|
||||||
_2,
|
_2,
|
||||||
PTR_FROM_THIS(),
|
PTR_FROM_THIS(Watcher),
|
||||||
connection,
|
connection,
|
||||||
fd);
|
fd);
|
||||||
return get_dispatch_wrapper(fn);
|
return get_dispatch_wrapper(fn);
|
||||||
|
|
@ -346,7 +346,7 @@ protected:
|
||||||
const auto fn = boost::bind(&Timer::timeout,
|
const auto fn = boost::bind(&Timer::timeout,
|
||||||
this,
|
this,
|
||||||
_1,
|
_1,
|
||||||
PTR_FROM_THIS(),
|
PTR_FROM_THIS(Timer),
|
||||||
connection,
|
connection,
|
||||||
timeout);
|
timeout);
|
||||||
|
|
||||||
|
|
@ -583,6 +583,16 @@ public:
|
||||||
* Destructor
|
* Destructor
|
||||||
*/
|
*/
|
||||||
~LibBoostAsioHandler() override = default;
|
~LibBoostAsioHandler() override = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure to stop the heartbeat timer after the connection is closed.
|
||||||
|
* Otherwise it will keep the service running forever.
|
||||||
|
*/
|
||||||
|
void onClosed(TcpConnection* connection) override
|
||||||
|
{
|
||||||
|
(void)connection;
|
||||||
|
_timer.reset();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue