drogon
drogon copied to clipboard
Ability for app to recover from an unavailable socket
Our app (X-Plane) embeds Drogon to provide a restful API for third party add-ons. When the listening port for API requests is not available (e.g. because it is in use or some other machine-specific failure causes ::bind to fail) Trantor calls exit(), terminating the entire app.
We would like to receive an error code from the attempt to create the listener so we can alert the user that web end points are not available and continue app launch.
We can code this ourselves! I have two questions:
- Would this kind of recoverability be desirable as a core feature of Drogon? E.g. should we create a pull request?
- If it is desirable, do you have a preference for how the recovery path is implemented?
From a brief look at the code, it looks like we could potentially throw an exception out of the "acceptor" constructor if bind fails, and eventually catch it where the listener shared ptr is created. Is the Drogon code base meant to be exception safe, or exception free (meaning, like, don't use them)?
The alternative non-exception implementation would be to have the state of the socket be visible (through the layers of objects) such that the listener-creating code could ask (after creating the listener) "did this thing init successfully, or is it a zombie", and then throw it out if it failed.