in proton-j/src/main/java/org/apache/qpid/proton/engine/impl/TransportImpl.java [428:481]
private void processDetach()
{
if(_connectionEndpoint != null && _isOpenSent)
{
EndpointImpl endpoint = _connectionEndpoint.getTransportHead();
while(endpoint != null)
{
if(endpoint instanceof LinkImpl)
{
LinkImpl link = (LinkImpl) endpoint;
TransportLink<?> transportLink = getTransportState(link);
SessionImpl session = link.getSession();
TransportSession transportSession = getTransportState(session);
if(((link.getLocalState() == EndpointState.CLOSED) || link.detached())
&& transportLink.isLocalHandleSet()
&& transportSession.isLocalChannelSet()
&& !_isCloseSent)
{
if((link instanceof SenderImpl)
&& link.getQueued() > 0
&& !transportLink.detachReceived()
&& !transportSession.endReceived()
&& !_closeReceived) {
endpoint = endpoint.transportNext();
continue;
}
UnsignedInteger localHandle = transportLink.getLocalHandle();
transportLink.clearLocalHandle();
transportSession.freeLocalHandle(localHandle);
Detach detach = new Detach();
detach.setHandle(localHandle);
detach.setClosed(!link.detached());
ErrorCondition localError = link.getCondition();
if( localError.getCondition() !=null )
{
detach.setError(localError);
}
writeFrame(transportSession.getLocalChannel(), detach, null, null);
transportLink.sentDetach();
}
endpoint.clearModified();
}
endpoint = endpoint.transportNext();
}
}
}