Beispiel #1
0
static void test_multmatch (flux_t h)
{
    flux_msg_handler_t *w1, *w2;
    struct flux_match m1 = FLUX_MATCH_ANY;
    struct flux_match m2 = FLUX_MATCH_ANY;

    m1.topic_glob = "foo.*";
    m2.topic_glob = "foo.bar";

    /* test #1: verify multiple match behaves as documented, that is,
     * a message is matched (only) by the most recently added watcher
     */
    ok ((w1 = flux_msg_handler_create (h, m1, multmatch1, NULL)) != NULL,
        "multmatch: first added handler for foo.*");
    ok ((w2 = flux_msg_handler_create (h, m2, multmatch2, NULL)) != NULL,
        "multmatch: next added handler for foo.bar");
    flux_msg_handler_start (w1);
    flux_msg_handler_start (w2);
    ok (send_request (h, "foo.bar") == 0,
        "multmatch: send foo.bar msg");
    ok (send_request (h, "foo.baz") == 0,
        "multmatch: send foo.baz msg");
    ok (flux_reactor_run (flux_get_reactor (h), 0) == 0 && multmatch_count == 2,
        "multmatch: last added watcher handled foo.bar");
    flux_msg_handler_destroy (w1);
    flux_msg_handler_destroy (w2);
}
Beispiel #2
0
int main (int argc, char **argv)
{
    flux_t h;
    heartbeat_t *hb;
    flux_msg_handler_t *w;

    plan (18);

    check_codec ();

    (void)setenv ("FLUX_CONNECTOR_PATH", CONNECTOR_PATH, 0);
    ok ((h = flux_open ("loop://", 0)) != NULL,
        "opened loop connector");
    if (!h)
        BAIL_OUT ("can't continue without loop handle");
    flux_fatal_set (h, fatal_err, NULL);

    ok ((hb = heartbeat_create ()) != NULL,
        "heartbeat_create works");

    heartbeat_set_flux (hb, h);

    ok (heartbeat_get_rate (hb) == 2.,
        "heartbeat_get_rate returns default of 2s");
    errno = 0;
    ok (heartbeat_set_rate (hb, -1) < 1 && errno == EINVAL,
        "heartbeat_set_rate -1 fails with EINVAL");
    errno = 0;
    ok (heartbeat_set_rate (hb, 1000000) < 1 && errno == EINVAL,
        "heartbeat_set_rate 1000000 fails with EINVAL");
    ok (heartbeat_set_ratestr (hb, "250ms") == 0,
        "heartbeat_set_ratestr 250ms works");
    ok (heartbeat_get_rate (hb) == 0.250,
        "heartbeat_get_rate returns what was set");
    ok (heartbeat_set_rate (hb, 0.1) == 0,
        "heartbeat_set_rate 0.1 works");
    ok (heartbeat_get_rate (hb) == 0.1,
        "heartbeat_get_rate returns what was set");

    ok (heartbeat_get_epoch (hb) == 0,
        "heartbeat_get_epoch works, default is zero");

    w = flux_msg_handler_create (h, FLUX_MATCH_EVENT, heartbeat_event_cb, hb);
    ok (w != NULL,
        "created event watcher");
    flux_msg_handler_start (w);

    ok (heartbeat_start (hb) == 0,
        "heartbeat_start works");

    ok (flux_reactor_run (flux_get_reactor (h), 0) == 0,
        "flux reactor exited normally");

    heartbeat_destroy (hb);
    flux_msg_handler_destroy (w);
    flux_close (h);

    done_testing ();
    return 0;
}
Beispiel #3
0
static void flux_rpc_usecount_decr (flux_rpc_t *rpc)
{
    if (!rpc)
        return;
    assert (rpc->magic == RPC_MAGIC);
    if (--rpc->usecount == 0) {
        if (rpc->w) {
            flux_msg_handler_stop (rpc->w);
            flux_msg_handler_destroy (rpc->w);
        }
        if (rpc->m.matchtag != FLUX_MATCHTAG_NONE) {
            /* FIXME: we cannot safely return matchtags to the pool here
             * if the rpc was not completed.  Lacking a proper cancellation
             * protocol, we simply leak them.  See issue #212.
             */
            if (rpc->rx_count >= rpc->rx_expected)
                flux_matchtag_free (rpc->h, rpc->m.matchtag);
        }
        flux_msg_destroy (rpc->rx_msg);
        if (rpc->aux && rpc->aux_destroy)
            rpc->aux_destroy (rpc->aux);
        rpc->magic =~ RPC_MAGIC;
        free (rpc);
    }
}
Beispiel #4
0
static void ping_finalize (void *arg)
{
    struct ping_context *p = arg;
    flux_msg_handler_stop (p->mh);
    flux_msg_handler_destroy (p->mh);
    free (p);
}
Beispiel #5
0
int flux_msg_handler_addvec (flux_t h, struct flux_msg_handler_spec tab[],
                             void *arg)
{
    int i;
    struct flux_match match = FLUX_MATCH_ANY;

    for (i = 0; ; i++) {
        if (!tab[i].typemask && !tab[i].topic_glob && !tab[i].cb)
            break; /* FLUX_MSGHANDLER_TABLE_END */
        match.typemask = tab[i].typemask;
        match.topic_glob = tab[i].topic_glob;
        tab[i].w = flux_msg_handler_create (h, match, tab[i].cb, arg);
        if (!tab[i].w)
            goto error;
        flux_msg_handler_start (tab[i].w);
    }
    return 0;
error:
    while (i >= 0) {
        if (tab[i].w) {
            flux_msg_handler_stop (tab[i].w);
            flux_msg_handler_destroy (tab[i].w);
            tab[i].w = NULL;
        }
        i--;
    }
    return -1;
}
Beispiel #6
0
void heartbeat_destroy (heartbeat_t *hb)
{
    if (hb) {
        flux_watcher_destroy (hb->timer);
        flux_msg_handler_destroy (hb->mh);
        free (hb);
    }
}
Beispiel #7
0
void shutdown_destroy (shutdown_t *s)
{
    if (s) {
        if (s->shutdown)
            flux_msg_handler_destroy (s->shutdown);
        if (s->h)
            (void)flux_event_unsubscribe (s->h, "shutdown");
        free (s);
    }
}
Beispiel #8
0
static void freectx (void *arg)
{
    ctx_t *ctx = arg;
    flux_msg_handler_t *w;
    while ((w = zlist_pop (ctx->handlers)))
        flux_msg_handler_destroy (w);
    zlist_destroy (&ctx->handlers);
    flux_watcher_destroy (ctx->w_prepare);
    flux_watcher_destroy (ctx->w_check);
    free (ctx);
}
Beispiel #9
0
static void cron_event_destroy (void *arg)
{
    struct cron_event *ev = arg;
    if (ev == NULL)
        return;

    if (ev->mh)
        flux_msg_handler_destroy (ev->mh);
    if (ev->h && ev->event)
        (void) flux_event_unsubscribe (ev->h, ev->event);
    free (ev->event);
    free (ev);
}
Beispiel #10
0
void flux_msg_handler_delvec (struct flux_msg_handler_spec tab[])
{
    int i;

    for (i = 0; ; i++) {
        if (!tab[i].typemask && !tab[i].topic_glob && !tab[i].cb)
            break; /* FLUX_MSGHANDLER_TABLE_END */
        if (tab[i].w) {
            flux_msg_handler_stop (tab[i].w);
            flux_msg_handler_destroy (tab[i].w);
            tab[i].w = NULL;
        }
    }
}
Beispiel #11
0
static void test_msg (flux_t h)
{
    flux_msg_handler_t *w;
    int i;

    ok ((w = flux_msg_handler_create (h, FLUX_MATCH_ANY, msgreader, NULL))
        != NULL,
        "msg: created handler for any message");
    flux_msg_handler_start (w);
    for (i = 0; i < msgwatcher_count; i++) {
        if (send_request (h, "foo") < 0)
            break;
    }
    ok (i == msgwatcher_count,
        "msg: sent %d requests", i);
    ok (flux_reactor_run (flux_get_reactor (h), 0) == 0,
        "msg: reactor ran to completion after %d requests", msgwatcher_count);
    flux_msg_handler_stop (w);
    flux_msg_handler_destroy (w);
}
Beispiel #12
0
static void flux_rpc_usecount_decr (flux_rpc_t *rpc)
{
    if (rpc && --rpc->usecount == 0) {
        if (rpc->w) {
            flux_msg_handler_stop (rpc->w);
            flux_msg_handler_destroy (rpc->w);
        }
        if (rpc->m.matchtag != FLUX_MATCHTAG_NONE) {
            /* FIXME: we cannot safely return matchtags to the pool here
             * if the rpc was not completed.  Lacking a proper cancellation
             * protocol, we simply leak them.  See issue #212.
             */
            if (flux_rpc_completed (rpc))
                flux_matchtag_free (rpc->h, rpc->m.matchtag, rpc->m.bsize);
        }
        flux_msg_destroy (rpc->rx_msg);
        flux_msg_destroy (rpc->rx_msg_consumed);
        if (rpc->nodemap)
            free (rpc->nodemap);
        if (rpc->aux && rpc->aux_destroy)
            rpc->aux_destroy (rpc->aux);
        free (rpc);
    }
}