Example #1
0
int module_sendmsg (module_t *p, const flux_msg_t *msg)
{
    flux_msg_t *cpy = NULL;
    int type;
    int rc = -1;

    if (!msg)
        return 0;
    if (flux_msg_get_type (msg, &type) < 0)
        goto done;
    switch (type) {
        case FLUX_MSGTYPE_REQUEST: { /* simulate DEALER socket */
            char uuid[16];
            snprintf (uuid, sizeof (uuid), "%u", p->rank);
            if (!(cpy = flux_msg_copy (msg, true)))
                goto done;
            if (flux_msg_push_route (cpy, uuid) < 0)
                goto done;
            if (flux_msg_sendzsock (p->sock, cpy) < 0)
                goto done;
            break;
        }
        case FLUX_MSGTYPE_RESPONSE: { /* simulate ROUTER socket */
            if (!(cpy = flux_msg_copy (msg, true)))
                goto done;
            if (flux_msg_pop_route (cpy, NULL) < 0)
                goto done;
            if (flux_msg_sendzsock (p->sock, cpy) < 0)
                goto done;
            break;
        }
        default:
            if (flux_msg_sendzsock (p->sock, msg) < 0)
                goto done;
            break;
    }
    rc = 0;
done:
    flux_msg_destroy (cpy);
    return rc;
}
Example #2
0
static int op_send (void *impl, const flux_msg_t *msg, int flags)
{
    ctx_t *ctx = impl;
    assert (ctx->magic == MODHANDLE_MAGIC);
    flux_msg_t *cpy = NULL;
    int type;
    int rc = -1;

    if (connect_socket (ctx) < 0)
        goto done;
    if (flux_msg_get_type (msg, &type) < 0)
        goto done;
    switch (type) {
    case FLUX_MSGTYPE_REQUEST:
    case FLUX_MSGTYPE_EVENT:
        if (!(cpy = flux_msg_copy (msg, true)))
            goto done;
        if (flux_msg_enable_route (cpy) < 0)
            goto done;
        if (flux_msg_push_route (cpy, ctx->uuid) < 0)
            goto done;
        if (flux_msg_sendzsock (ctx->sock, cpy) < 0)
            goto done;
        break;
    case FLUX_MSGTYPE_RESPONSE:
    case FLUX_MSGTYPE_KEEPALIVE:
        if (flux_msg_sendzsock (ctx->sock, msg) < 0)
            goto done;
        break;
    default:
        errno = EINVAL;
        goto done;
    }
    rc = 0;
done:
    flux_msg_destroy (cpy);
    return rc;
}
Example #3
0
/* Send shutdown request, broker to module.
 */
int module_stop (module_t *p, const flux_msg_t *rmmod)
{
    assert (p->magic == MODULE_MAGIC);
    char *topic = xasprintf ("%s.shutdown", p->name);
    flux_msg_t *msg;
    int rc = -1;

    if (!(msg = flux_msg_create (FLUX_MSGTYPE_REQUEST)))
        goto done;
    if (flux_msg_set_topic (msg, topic) < 0)
        goto done;
    if (flux_msg_sendzsock (p->sock, msg) < 0)
        goto done;
    if (rmmod) {
        flux_msg_t *cpy = flux_msg_copy (rmmod, true);
        if (!cpy || zlist_append (p->rmmod, cpy) < 0)
            oom ();
    }
    rc = 0;
done:
    free (topic);
    flux_msg_destroy (msg);
    return rc;
}