[daemon] margo-related calls should be abstracted in dedicated class
At the moment daemon/handler/rpc_util.cpp
templates margo respond and cleanup code. To reduce complexity, add a class for margo-related calls that are used in handlers so that cleanup is easier.
Below suggestion of Alberto: Coming back to my first comment about RAII, this would probably benefit from a helper class similar to:
template <typename InputTp, typename OutputTp>
class margo_rpc_context {
// we can also have several constructor overloads for rpcs with bulk handles, without output, etc.
margo_rpc_context(hg_handle_t h, InputTp&& input, OutputTp&& output) {
// save stuff
}
~margo_rpc_context() {
// cleanup stuff
}
};
This would allow us to do the following:
auto ctx = margo_rpc_context(h, in, out);
We could then pass the ctx
around as needed and all the margo stuff would be automatically cleaned up when the function returns, regardless of whether it's an error, and exception or the normal control flow. This would allow us to get rid of the cleanup
calls.