make sure onLost and onDetached are always called
This commit is contained in:
parent
0d42234a3d
commit
2496dbbd4e
|
|
@ -231,7 +231,8 @@ public:
|
||||||
* pending operations are completed, and then an AMQP closing-handshake is
|
* pending operations are completed, and then an AMQP closing-handshake is
|
||||||
* performed. If you pass a parameter "immediate=true" the connection is
|
* performed. If you pass a parameter "immediate=true" the connection is
|
||||||
* immediately closed, without waiting for earlier commands (and your handler's
|
* immediately closed, without waiting for earlier commands (and your handler's
|
||||||
* onError() method is called about the premature close)
|
* onError() method is called about the premature close, including the onLost() and
|
||||||
|
* onDetached()).
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
bool close(bool immediate = false);
|
bool close(bool immediate = false);
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,8 @@ void TcpConnection::process(int fd, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the connection
|
* Close the connection.
|
||||||
|
* Warning: this potentially directly calls several handlers (onError, onLost, onDetached)
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
bool TcpConnection::close(bool immediate)
|
bool TcpConnection::close(bool immediate)
|
||||||
|
|
@ -140,10 +141,17 @@ bool TcpConnection::close(bool immediate)
|
||||||
|
|
||||||
// stop if object was destructed
|
// stop if object was destructed
|
||||||
if (!monitor.valid()) return true;
|
if (!monitor.valid()) return true;
|
||||||
|
|
||||||
|
// also call the lost handler, we have now lost the connection from this state (since we force-closed).
|
||||||
|
// this makes sure the onLost and onDetached is properly called.
|
||||||
|
onLost(_state.get());
|
||||||
|
|
||||||
|
// stop if object was destructed
|
||||||
|
if (!monitor.valid()) return true;
|
||||||
|
|
||||||
// change the state
|
// change the state
|
||||||
_state.reset(new TcpClosed(this));
|
_state.reset(new TcpClosed(this));
|
||||||
|
|
||||||
// done, we return true because the connection is closed
|
// done, we return true because the connection is closed
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue