From 6f81b0a097cecb5025a71edc5657121c51c3bc18 Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Sun, 11 Nov 2018 23:46:58 +0100 Subject: [PATCH] when tcp connection is lost, the pending operations are now reported with an error --- include/amqpcpp/linux_tcp/tcpconnection.h | 2 +- src/linux_tcp/tcpconnection.cpp | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/amqpcpp/linux_tcp/tcpconnection.h b/include/amqpcpp/linux_tcp/tcpconnection.h index 29f2122..0beed23 100644 --- a/include/amqpcpp/linux_tcp/tcpconnection.h +++ b/include/amqpcpp/linux_tcp/tcpconnection.h @@ -259,7 +259,7 @@ public: */ std::size_t channels() const { - // return the amount of channels this connection has + // return the number of channels this connection has return _connection.channels(); } diff --git a/src/linux_tcp/tcpconnection.cpp b/src/linux_tcp/tcpconnection.cpp index 51067af..9ce612e 100644 --- a/src/linux_tcp/tcpconnection.cpp +++ b/src/linux_tcp/tcpconnection.cpp @@ -199,13 +199,18 @@ void TcpConnection::onClosed(Connection *connection) */ void TcpConnection::onError(TcpState *state, const char *message, bool connected) { - // if the object is still connected, we only have to report the error and - // we wait for the subsequent call to the onClosed() method - if (connected) return _handler->onError(this, message); - - // no extra onClosed() call is expected, so we have to report multiple things - // to user-space, we use a monitor to check if "this" is destructed in the middle + // monitor to check if all operations are active Monitor monitor(this); + + // if there are still pending operations, they should be reported as error + _connection.fail(message); + + // stop if object was destructed + if (!monitor.valid()) return; + + // if the object is still connected, we only have to report the error and + // we wait for the subsequent call to the onLost() method + if (connected) return _handler->onError(this, message); // tell the handler _handler->onError(this, message); @@ -225,7 +230,7 @@ void TcpConnection::onLost(TcpState *state) { // monitor to check if "this" is destructed Monitor monitor(this); - + // tell the handler _handler->onLost(this);