when tcp connection is lost, the pending operations are now reported with an error

This commit is contained in:
Emiel Bruijntjes 2018-11-11 23:46:58 +01:00
parent 8d08916b8c
commit 6f81b0a097
2 changed files with 13 additions and 8 deletions

View File

@ -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();
}

View File

@ -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);