A previous question How to get Disconnect Event from GATT Server on Bluez/Linux addresses the disconnect event for Bluez stack.
However since the disconnection detection is at the GATT layer it takes a while for the disconnection to be detected at the GATT Layer. Delayed disconnection detection would be an issue for many applications.
Bluez provides HCI API to connect/disconnect at BLE layer:
int hci_le_create_conn();
int hci_disconnect();
How does an application catch an HCI event indicating that a BLE connection made by hci_le_create_conn() is now disconnected.