Example #1
0
static int rpc_request_send (flux_rpc_t *rpc, int n, const char *topic,
                             const char *json_str, uint32_t nodeid)
{
    flux_msg_t *msg;
    int flags = 0;
    int rc = -1;

    if (!(msg = flux_request_encode (topic, json_str)))
        goto done;
    if (flux_msg_set_matchtag (msg, rpc->m.matchtag + n) < 0)
        goto done;
    if (nodeid == FLUX_NODEID_UPSTREAM) {
        flags |= FLUX_MSGFLAG_UPSTREAM;
        if (flux_get_rank (rpc->h, &nodeid) < 0)
            goto done;
    }
    if (flux_msg_set_nodeid (msg, nodeid, flags) < 0)
        goto done;
    if (flux_send (rpc->h, msg, 0) < 0)
        goto done;
    rc = 0;
done:
    if (msg)
        flux_msg_destroy (msg);
    return rc;
}
Example #2
0
static int rpc_request_prepare (flux_rpc_t *rpc, flux_msg_t *msg,
                                uint32_t nodeid)
{
    int flags = 0;
    int rc = -1;
    uint32_t matchtag = rpc->m.matchtag & ~FLUX_MATCHTAG_GROUP_MASK;
    uint32_t matchgrp = rpc->m.matchtag & FLUX_MATCHTAG_GROUP_MASK;

    /* So that flux_rpc_get_nodeid() can get nodeid from a response:
     * For group rpc, use the lower matchtag bits to stash the nodeid
     * in the request, and it will come back in the response.
     * For singleton rpc, stash destination nodeid in rpc->nodeid.
     * TODO-scalability: If nodeids exceed 1<<20, we may need to use a seq#
     * in lower matchtag bits and stash a mapping array inthe rpc object.
     */
    if (matchgrp > 0) {
        if ((nodeid & FLUX_MATCHTAG_GROUP_MASK) != 0) {
            errno = ERANGE;
            goto done;
        }
        matchtag = matchgrp | nodeid;
    } else
        rpc->nodeid = nodeid;
    if (flux_msg_set_matchtag (msg, matchtag) < 0)
        goto done;
    if (nodeid == FLUX_NODEID_UPSTREAM) {
        flags |= FLUX_MSGFLAG_UPSTREAM;
        if (flux_get_rank (rpc->h, &nodeid) < 0)
            goto done;
    }
    if (flux_msg_set_nodeid (msg, nodeid, flags) < 0)
        goto done;
    rc = 0;
done:
    return rc;
}