UnsignedInteger localHandle = transportLink.getLocalHandle();
transportLink.clearLocalHandle();
transportSession.freeLocalHandle(localHandle);
Detach detach = new Detach();
detach.setHandle(localHandle);
// TODO - need an API for detaching rather than closing the link
detach.setClosed(true);
EndpointError localError = link.getLocalError();
if( localError !=null ) {
ErrorCondition error = new ErrorCondition();
error.setCondition(Symbol.getSymbol(localError.getName()));
error.setDescription(localError.getDescription());
detach.setError(error);
}
int frameBytes = writeFrame(buffer, transportSession.getLocalChannel(), detach, null, null);
written += frameBytes;