Пример #1
0
static test_return_t clone_test(hashkit_st *hashk)
{
  // First we make sure that the testing system is giving us what we expect.
  assert(&global_hashk == hashk);

  // Second we test if hashk is even valid

  /* All null? */
  {
    hashkit_st *hashk_ptr;
    hashk_ptr= hashkit_clone(NULL, NULL);
    test_true(hashk_ptr);
    test_true(hashkit_is_allocated(hashk_ptr));
    hashkit_free(hashk_ptr);
  }

  /* Can we init from null? */
  {
    hashkit_st *hashk_ptr;

    hashk_ptr= hashkit_clone(NULL, hashk);

    test_true(hashk_ptr);
    test_true(hashkit_is_allocated(hashk_ptr));

    hashkit_free(hashk_ptr);
  }

  /* Can we init from struct? */
  {
    hashkit_st declared_clone;
    hashkit_st *hash_clone;

    hash_clone= hashkit_clone(&declared_clone, NULL);
    test_true(hash_clone);
    test_true(hash_clone == &declared_clone);
    test_false(hashkit_is_allocated(hash_clone));

    hashkit_free(hash_clone);
  }

  /* Can we init from struct? */
  {
    hashkit_st declared_clone;
    hashkit_st *hash_clone;

    hash_clone= hashkit_clone(&declared_clone, hashk);
    test_true(hash_clone);
    test_true(hash_clone == &declared_clone);
    test_false(hashkit_is_allocated(hash_clone));

    hashkit_free(hash_clone);
  }

  return TEST_SUCCESS;
}
Пример #2
0
memcached_return_t memcached_set_hashkit(memcached_st *self, hashkit_st *hashk)
{
  hashkit_free(&self->hashkit);
  hashkit_clone(&self->hashkit, hashk);

  return MEMCACHED_SUCCESS;
}
Пример #3
0
    Hashkit& operator=(const Hashkit& source)
    {
        hashkit_free(&self);
        hashkit_clone(&self, &source.self);

        return *this;
    }
Пример #4
0
static test_return_t hashkit_compare_test(hashkit_st *hashk)
{
  hashkit_st *clone;

  clone= hashkit_clone(NULL, hashk);

  test_true(hashkit_compare(clone, hashk));
  hashkit_free(clone);

  return TEST_SUCCESS;
}
Пример #5
0
/*
  clone is the destination, while source is the structure to clone.
  If source is NULL the call is the same as if a memcached_create() was
  called.
*/
memcached_st *memcached_clone(memcached_st *clone, const memcached_st *source)
{
  memcached_return_t rc= MEMCACHED_SUCCESS;
  memcached_st *new_clone;

  if (source == NULL)
    return memcached_create(clone);

  if (clone && memcached_is_allocated(clone))
  {
    return NULL;
  }

  new_clone= memcached_create(clone);

  if (new_clone == NULL)
    return NULL;

  new_clone->flags= source->flags;
  new_clone->send_size= source->send_size;
  new_clone->recv_size= source->recv_size;
  new_clone->poll_timeout= source->poll_timeout;
  new_clone->connect_timeout= source->connect_timeout;
  new_clone->retry_timeout= source->retry_timeout;
  new_clone->distribution= source->distribution;

  hashkit_st *hash_ptr;

  hash_ptr= hashkit_clone(&new_clone->hashkit, &source->hashkit);
  if (! hash_ptr)
  {
    memcached_free(new_clone);
    return NULL;
  }

  hash_ptr= hashkit_clone(&new_clone->distribution_hashkit, &source->distribution_hashkit);
  if (! hash_ptr)
  {
    memcached_free(new_clone);
    return NULL;
  }

  new_clone->user_data= source->user_data;

  new_clone->snd_timeout= source->snd_timeout;
  new_clone->rcv_timeout= source->rcv_timeout;

  new_clone->on_clone= source->on_clone;
  new_clone->on_cleanup= source->on_cleanup;

  new_clone->allocators= source->allocators;

  new_clone->get_key_failure= source->get_key_failure;
  new_clone->delete_trigger= source->delete_trigger;
  new_clone->server_failure_limit= source->server_failure_limit;
  new_clone->io_msg_watermark= source->io_msg_watermark;
  new_clone->io_bytes_watermark= source->io_bytes_watermark;
  new_clone->io_key_prefetch= source->io_key_prefetch;
  new_clone->number_of_replicas= source->number_of_replicas;

  if (memcached_server_list(source))
    rc= memcached_server_push(new_clone, memcached_server_list(source));

  if (rc != MEMCACHED_SUCCESS)
  {
    memcached_free(new_clone);

    return NULL;
  }


  if (source->prefix_key_length)
  {
    strcpy(new_clone->prefix_key, source->prefix_key);
    new_clone->prefix_key_length= source->prefix_key_length;
  }

  rc= run_distribution(new_clone);

  if (rc != MEMCACHED_SUCCESS)
  {
    memcached_free(new_clone);

    return NULL;
  }

  if (source->on_clone)
    source->on_clone(new_clone, source);

  return new_clone;
}
Пример #6
0
 Hashkit(const Hashkit& source)
 {
     hashkit_clone(&self, &source.self);
 }