예제 #1
0
/*
 * Opens the database environment.
 *
 * ARGUMENTS:
 *      path            Pathname of the database directory.  Shall not be NULL.
 *                      The client can free it upon return.
 *      dbEnv           Pointer to a pointer to the database environment.  Shall
 *                      not be NULL.  "*dbEnv" is set upon successful return.
 * RETURNS:
 *      0               Success.  "*dbEnv" is set.
 *      ENOMEM          System error.  "log_add()" called.
 *      EIO             Backend database error.  "log_add()" called.
 */
static RegStatus
openEnvironment(
    const char* const   path,
    DB_ENV** const      dbEnv)
{
    RegStatus   status;
    DB_ENV*     env;

    assert(NULL != path);

    log_list_clear();

    if (0 == (status = createEnvHandle(path, &env))) {
        /*
         * The database is configured for "concurrent data store"
         * access rather than for transactional access because the
         * former is faster and sufficient.
         */
        status = env->open(env, path, DB_CREATE | DB_INIT_CDB | DB_INIT_MPOOL,
            0);

        if (status) {
            log_add("Couldn't open environment for database \"%s\"", path);
            status = EIO;
        }
        else {
            *dbEnv = env;
        }

        if (status)
            (void)env->close(env, 0);
    }                                   /* "env" allocated */

    return status;
}
예제 #2
0
/*
 * Closes the cursor.
 *
 * Arguments:
 *      backend         Pointer to the backend database.  Shall not be NULL.
 * Returns:
 *      0               Success.
 *      EIO             Backend database error.  "log_add()" called.
 */
static RegStatus closeCursor(
    Backend* const       backend)
{
    RegStatus           status = 0;     /* success */
    Cursor* const       cursor = &backend->cursor;
    DBC* const          dbCursor = cursor->dbCursor;

    if (dbCursor) {
        log_list_clear();

        if (status = dbCursor->close(dbCursor)) {
            log_add("Couldn't close cursor for database \"%s\"",
                getPath(backend->db));
            status = EIO;
        }
        else {
            free(cursor->key.data);
            free(cursor->value.data);
            cursor->key.data = NULL;
            cursor->value.data = NULL;
            cursor->dbCursor = NULL;
        }
    }

    return status;
}
예제 #3
0
/*
 * Creates a database environment handle
 *
 * ARGUMENTS:
 *      path            Pathname of the database directory.  Shall not be NULL.
 *                      The client can free it upon return.
 *      dbEnv           Pointer to a pointer to the database environment.  Shall
 *                      not be NULL.  "*dbEnv" is set upon successful return.
 * RETURNS:
 *      0               Success.  "*dbEnv" is set.
 *      ENOMEM          System error.  "log_add()" called.
 *      EIO             Backend database error.  "log_add()" called.
 */
static RegStatus
createEnvHandle(
    const char* const   path,
    DB_ENV** const      dbEnv)
{
    RegStatus   status;
    DB_ENV*     env;

    assert(NULL != path);

    log_list_clear();

    if (status = db_env_create(&env, 0)) {
        log_syserr("Couldn't create environment handle for database: %s",
            db_strerror(status));
        status = ENOMEM;
    }
    else {
        env->set_errcall(env, logDbError);

        if (status = env->set_isalive(env, is_alive)) {
            log_add("Couldn't register \"is_alive()\" function for "
                "database \"%s\"", path);
            status = EIO;
        }
        else {
            static const unsigned      threadCount = 256;

            if (status = env->set_thread_count(env, threadCount)) {
                log_add("Couldn't set thread count to %u for database \"%s\"",
                    threadCount, path);
                status = EIO;
            }
            else {
                *dbEnv = env;
            }
        }

        if (status)
            (void)env->close(env, 0);
    }                                   /* "env" allocated */

    return status;
}
예제 #4
0
파일: mcast_test.cpp 프로젝트: Unidata/LDM
void test_fmtpReceiver_new()
{
    int                         status;
    FmtpReceiver*              receiver;
    const char*                 addr = "224.0.0.1";
    const unsigned short        port = 1;
    const char* const           tcpAddr = "127.0.0.1";
    const unsigned short        tcpPort = 38800;

    status = mcastReceiver_new(NULL, tcpAddr, tcpPort, bof_func, eof_func,
            missed_file_func, addr, port, NULL);
    OP_ASSERT_EQUAL_INT(EINVAL, status);
    log_list_clear();
    status = mcastReceiver_new(&receiver, tcpAddr, tcpPort, NULL, eof_func,
            missed_file_func, addr, port, NULL);
    OP_ASSERT_EQUAL_INT(EINVAL, status);
    log_list_clear();
    status = mcastReceiver_new(&receiver, tcpAddr, tcpPort, bof_func, NULL,
            missed_file_func, addr, port, NULL);
    OP_ASSERT_EQUAL_INT(EINVAL, status);
    log_list_clear();
    status = mcastReceiver_new(&receiver, tcpAddr, tcpPort, bof_func, eof_func,
            NULL, addr, port, NULL);
    OP_ASSERT_EQUAL_INT(EINVAL, status);
    log_list_clear();
    status = mcastReceiver_new(&receiver, tcpAddr, tcpPort, bof_func, eof_func,
            missed_file_func, NULL, port, NULL);
    OP_ASSERT_EQUAL_INT(EINVAL, status);
    log_list_clear();

    status = mcastReceiver_new(&receiver, tcpAddr, tcpPort, bof_func, eof_func,
            missed_file_func, addr, port, NULL);
    OP_ASSERT_EQUAL_INT(0, status);
    log_list_clear();

    OP_VERIFY();
}