示例#1
0
static ENGINE_ERROR_CODE mock_item_allocate(ENGINE_HANDLE* handle,
        const void* cookie,
        item **it,
        const void* key,
        const size_t nkey,
        const size_t nbytes,
        const int flags,
        const rel_time_t exptime) {

    // Only perform allocations if there's a hashtable.
    if (get_ht(handle) != NULL) {
        size_t to_alloc = sizeof(item) + nkey + nbytes;
        *it = calloc(to_alloc, 1);
    } else {
        *it = NULL;
    }
    // If an allocation was requested *and* worked, fill and report success
    if (*it) {
        item *i = *it;
        i->exptime = exptime;
        i->nbytes = nbytes;
        i->flags = flags;
        i->nkey = nkey;
        memcpy((char*)item_get_key(i), key, nkey);
        return ENGINE_SUCCESS;
    } else {
        return ENGINE_ENOMEM;
    }
}
示例#2
0
static ENGINE_ERROR_CODE mock_flush(ENGINE_HANDLE* handle,
                                    const void* cookie, time_t when) {
    (void)cookie;
    (void)when;
    genhash_clear(get_ht(handle));
    return ENGINE_SUCCESS;
}
示例#3
0
void dispatch(int fd, int* to_copy, fd_set* master) {
    entry_send* es = (entry_send*)get_ht(&ht,fd);
    int rv = do_action[es->stage](es);
    if (rv == -1 || es->data_sent>=es->size) {
        (*to_copy)--;
        close_connection(es,master);
    }
}
示例#4
0
static ENGINE_ERROR_CODE mock_store(ENGINE_HANDLE* handle,
                                    const void *cookie,
                                    item* item,
                                    uint64_t *cas,
                                    ENGINE_STORE_OPERATION operation) {
    genhash_update(get_ht(handle), item_get_key(item), item->nkey, item, 0);
    return ENGINE_SUCCESS;
}
示例#5
0
static ENGINE_ERROR_CODE mock_get(ENGINE_HANDLE* handle,
                                  const void* cookie,
                                  item** item,
                                  const void* key,
                                  const int nkey) {
    *item = genhash_find(get_ht(handle), key, nkey);

    return *item ? ENGINE_SUCCESS : ENGINE_KEY_ENOENT;
}
示例#6
0
static ENGINE_ERROR_CODE mock_item_delete(ENGINE_HANDLE* handle,
                                          const void* cookie,
                                          const void* key,
                                          const size_t nkey,
                                          uint64_t cas,
                                          uint16_t vbucket) {
    int r = genhash_delete_all(get_ht(handle), key, nkey);
    return r > 0 ? ENGINE_SUCCESS : ENGINE_KEY_ENOENT;
}
示例#7
0
static ENGINE_ERROR_CODE mock_get(ENGINE_HANDLE* handle,
                                  const void* cookie,
                                  item** itm,
                                  const void* key,
                                  const int nkey,
                                  uint16_t vbucket) {
    (void)cookie;
    (void)vbucket;
    *itm = genhash_find(get_ht(handle), key, nkey);

    return *itm ? ENGINE_SUCCESS : ENGINE_KEY_ENOENT;
}
示例#8
0
static ENGINE_ERROR_CODE mock_store(ENGINE_HANDLE* handle,
                                    const void *cookie,
                                    item* itm,
                                    uint64_t *cas,
                                    ENGINE_STORE_OPERATION operation,
                                    uint16_t vbucket) {
    (void)cookie;
    (void)cas;
    (void)vbucket;
    (void)operation;
    mock_item* it = (mock_item*)itm;
    genhash_update(get_ht(handle), item_get_key(itm), it->nkey, itm, 0);
    return ENGINE_SUCCESS;
}
示例#9
0
static ENGINE_ERROR_CODE mock_item_delete(ENGINE_HANDLE* handle,
        const void* cookie,
        item* item) {
    int r = genhash_delete_all(get_ht(handle), item_get_key(item), item->nkey);
    return r > 0 ? ENGINE_SUCCESS : ENGINE_KEY_ENOENT;
}