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
|
||||
* performed. If you pass a parameter "immediate=true" the connection is
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
bool TcpConnection::close(bool immediate)
|
||||
|
|
@ -140,10 +141,17 @@ bool TcpConnection::close(bool immediate)
|
|||
|
||||
// stop if object was destructed
|
||||
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
|
||||
_state.reset(new TcpClosed(this));
|
||||
|
||||
|
||||
// done, we return true because the connection is closed
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue