static void ebb_connection_info_destroy(ebb_connection_info *conninfo)
{
    if (conninfo != NULL)
    {
        ebb_connection_info_rsp_q_destroyall(conninfo->rsp_q);
        if (conninfo->errorbody != NULL)
            free(conninfo->errorbody);
        if (conninfo->managed_str != NULL)
            free(conninfo->managed_str);
        if (conninfo->streamids != NULL)
            idset_destroy(conninfo->streamids);
        if (conninfo->rsp_q != NULL)
            tailq_destroy(conninfo->rsp_q);
        free(conninfo);
    }
}
Esempio n. 2
0
struct idset *idset_decode (const char *str)
{
    struct idset *idset;
    char *cpy = NULL;
    char *tok, *saveptr, *a1;
    int saved_errno;

    if (!str) {
        errno = EINVAL;
        return NULL;
    }
    if (!(idset = idset_create (0, IDSET_FLAG_AUTOGROW)))
        return NULL;
    if (!(cpy = strdup (str)))
        goto error;
    a1 = trim_brackets (cpy);
    saveptr = NULL;
    while ((tok = strtok_r (a1, ",", &saveptr))) {
        unsigned int hi, lo, i;
        if (parse_range (tok, &hi, &lo) < 0)
            goto inval;
        /* Count backwards so that idset_set() can grow the
         * idset to the maximum size on the first access,
         * rather than possibly doing it multiple times.
         */
        for (i = hi; i >= lo && i != UINT_MAX; i--) {
            if (idset_set (idset, i) < 0)
                goto error;
        }
        a1 = NULL;
    }
    free (cpy);
    return idset;
inval:
    errno = EINVAL;
error:
    saved_errno = errno;
    idset_destroy (idset);
    free (cpy);
    errno = saved_errno;
    return NULL;
}
Esempio n. 3
0
static void rnode_alloc_and_check (struct rnode *n, int count, char *expected)
{
    struct idset *ids = NULL;
    char *result = NULL;
    int avail = rnode_avail (n);
    ok (rnode_alloc (n, count, &ids) == 0,
        "rnode_alloc: count=%d", count);
    ok (ids != NULL,
        "rnode_alloc: returns non-null idset");
    ok (idset_count (ids) == count,
        "rnode_alloc: returned idset with expected count (%d)",
        idset_count (ids));
    if (!(result = idset_encode (ids, IDSET_FLAG_RANGE)))
        BAIL_OUT ("failed to encode idset result");
    is (result, expected,
        "rnode_alloc: count=%d: returned expected result %s", count, result);
    ok (rnode_avail (n) == avail - count,
        "rnode_alloc: rnode_avail now %d, expected %d",
        rnode_avail (n), avail - count);
    idset_destroy (ids);
    free (result);
}
Esempio n. 4
0
int main (int ac, char *av[])
{
    struct idset *ids = NULL;
    struct rnode *n = NULL;

    plan (NO_PLAN);

    if (!(n = rnode_create (0, "0-3")))
        BAIL_OUT ("could not create an rnode object");
    ok (rnode_avail (n) == 4,
        "rnode_avail == 4");

    ok (rnode_alloc (n, 5, &ids) < 0 && errno == ENOSPC,
        "rnode_alloc too many cores returns errno ENOSPC");

    rnode_alloc_and_check (n, 1, "0");
    ok (rnode_avail (n) == 3,
        "rnode_avail == 3");
    rnode_avail_check (n, "1-3");

    rnode_alloc_and_check (n, 1, "1");
    ok (rnode_avail (n) == 2,
        "rnode_avail == 2");
    rnode_avail_check (n, "2-3");

    rnode_alloc_and_check (n, 2, "2-3");
    ok (rnode_avail (n) == 0,
        "rnode_avail == 0");
    rnode_avail_check (n, "");

    ok (rnode_alloc (n, 1, &ids) < 0 && errno == ENOSPC && ids == NULL,
        "rnode_alloc on empty rnode fails with ENOSPC");

    ok (rnode_free (n, "3-4") < 0 && errno == ENOENT,
        "rnode_free with invalid ids fails");
    ok (rnode_avail (n) == 0,
        "rnode_avail still is 0");
    rnode_avail_check (n, "");

    ok (rnode_free (n, "0-1") == 0,
        "rnode_free (0-1) works");
    ok (rnode_avail (n) == 2,
        "rnode_avail now is 2");
    rnode_avail_check (n, "0-1");
    ok (rnode_free (n, "0") < 0 && errno == EEXIST,
        "rnode_free of already available id fails");
    ok (rnode_avail (n) == 2,
        "rnode_avail is still 2");
    ok (rnode_free (n, "3") == 0,
        "rnode_free '3' works");
    rnode_avail_check (n, "0-1,3");

    rnode_alloc_and_check (n, 3, "0-1,3");

    rnode_destroy (n);

    n = rnode_create_count (1, 8);
    if (n == NULL)
        BAIL_OUT ("rnode_create_count failed");
    ok (n->rank == 1, "rnode rank set correctly");
    ok (n != NULL, "rnode_create_count");
    rnode_avail_check (n, "0-7");
    rnode_destroy (n);

    struct idset *idset = idset_decode ("0-3");
    n = rnode_create_idset (3, idset);
    idset_destroy (idset);
    if (n == NULL)
        BAIL_OUT ("rnode_create_idset failed");
    ok (n != NULL, "rnode_create_idset");
    ok (n->rank == 3, "rnode rank set correctly");
    rnode_avail_check (n, "0-3");

    struct idset *alloc = idset_decode ("1,3");
    ok (rnode_alloc_idset (n, alloc) == 0,
        "rnode_alloc_idset (1,3)");
    rnode_avail_check (n, "0,2");
    ok (rnode_alloc_idset (n, alloc) < 0 && errno == EEXIST,
        "rnode_alloc_idset with idset already allocated returns EEXIST");

    ok (rnode_free_idset (n, alloc) == 0,
        "rnode_free_idset (1,3)");
    rnode_avail_check (n, "0-3");

    ok (rnode_free_idset (n, alloc) < 0 && errno == EEXIST,
        "rnode_free_idset with idset already available returns EEXIST");

    idset_destroy (alloc);
    alloc = idset_decode ("4-7");
    ok (rnode_alloc_idset (n, alloc) < 0 && errno == ENOENT,
        "rnode_alloc_idset with invalid ids return ENOENT");
    ok (rnode_free_idset (n, alloc) < 0 && errno == ENOENT,
        "rnode_free_idset with invalid ids return ENOENT");

    idset_destroy (alloc);
    rnode_destroy (n);
    done_testing ();
}