Unverified Commit ce28b4b0 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

Refactor client rpc stat function

parent 4077fcf1
Loading
Loading
Loading
Loading
+25 −21
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ int rpc_send_stat(const std::string& path, string& attr) {
    hg_handle_t handle;
    rpc_path_only_in_t in{};
    rpc_stat_out_t out{};
    int err = EUNKNOWN;
    int err = 0;
    // fill in
    in.path = path.c_str();
    ld_logger->debug("{}() Creating Mercury handle ...", __func__);
@@ -143,29 +143,33 @@ int rpc_send_stat(const std::string& path, string& attr) {
    ret = margo_forward_timed_wrap(handle, &in);
#endif
    // Get response
    if (ret == HG_SUCCESS) {
        ld_logger->trace("{}() Waiting for response", __func__);
    if (ret != HG_SUCCESS) {
        errno = EBUSY;
        ld_logger->warn("{}() timed out");
        margo_destroy(handle);
        return -1;
    }

    ret = margo_get_output(handle, &out);
        if (ret == HG_SUCCESS) {
    if (ret != HG_SUCCESS) {
        ld_logger->error("{}() while getting rpc output", __func__);
        errno = EBUSY;
        margo_free_output(handle, &out);
        margo_destroy(handle);
        return -1;
    }

    ld_logger->debug("{}() Got response success: {}", __func__, out.err);
            if (out.err == 0) {
                err = 0;
                attr = out.db_val;
            } else {

    if(out.err != 0) {
        err = -1;
        errno = out.err;
            }
    } else {
            // something is wrong
            errno = EBUSY;
            ld_logger->error("{}() while getting rpc output", __func__);
        attr = out.db_val;
    }

    /* clean up resources consumed by this rpc */
    margo_free_output(handle, &out);
    } else {
        ld_logger->warn("{}() timed out");
        errno = EBUSY;
    }
    margo_destroy(handle);
    return err;
}