when tcp connection is lost, the pending operations are now reported with an error
This commit is contained in:
parent
8d08916b8c
commit
6f81b0a097
|
|
@ -259,7 +259,7 @@ public:
|
||||||
*/
|
*/
|
||||||
std::size_t channels() const
|
std::size_t channels() const
|
||||||
{
|
{
|
||||||
// return the amount of channels this connection has
|
// return the number of channels this connection has
|
||||||
return _connection.channels();
|
return _connection.channels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -199,13 +199,18 @@ void TcpConnection::onClosed(Connection *connection)
|
||||||
*/
|
*/
|
||||||
void TcpConnection::onError(TcpState *state, const char *message, bool connected)
|
void TcpConnection::onError(TcpState *state, const char *message, bool connected)
|
||||||
{
|
{
|
||||||
// if the object is still connected, we only have to report the error and
|
// monitor to check if all operations are active
|
||||||
// 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 monitor(this);
|
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
|
// tell the handler
|
||||||
_handler->onError(this, message);
|
_handler->onError(this, message);
|
||||||
|
|
@ -225,7 +230,7 @@ void TcpConnection::onLost(TcpState *state)
|
||||||
{
|
{
|
||||||
// monitor to check if "this" is destructed
|
// monitor to check if "this" is destructed
|
||||||
Monitor monitor(this);
|
Monitor monitor(this);
|
||||||
|
|
||||||
// tell the handler
|
// tell the handler
|
||||||
_handler->onLost(this);
|
_handler->onLost(this);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue