{
case MEMCACHED_CALLBACK_PREFIX_KEY:
{
- return memcached_set_namespace(ptr, (char*)data, data ? strlen((char*)data) : 0);
+ return memcached_set_namespace(*ptr, (char*)data, data ? strlen((char*)data) : 0);
}
case MEMCACHED_CALLBACK_USER_DATA:
#ifdef __cplusplus
# include "libmemcached/response.h"
+# include "libmemcached/namespace.h"
+#else
+# include "libmemcached/virtual_bucket.h"
#endif
-#include "libmemcached/namespace.h"
-#include "libmemcached/virtual_bucket.h"
-
#ifdef __cplusplus
# include "libmemcached/backtrace.hpp"
# include "libmemcached/assert.hpp"
parser_abort(context, "--NAMESPACE can only be called once");
}
- if ((context->rc= memcached_set_namespace(context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
+ if ((context->rc= memcached_set_namespace(*context->memc, $2.c_str, $2.size)) != MEMCACHED_SUCCESS)
{
parser_abort(context, memcached_last_error_message(context->memc));
}
*
* Libmemcached library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#include <libmemcached/common.h>
#include <libmemcached/assert.hpp>
-static void _set_encoding_key(Memcached& self, const char *key, size_t key_length)
+static void _set_encoding_key(Memcached& memc, const char *key, size_t key_length)
{
- hashkit_key(&self.hashkit, key, key_length);
+ hashkit_key(&memc.hashkit, key, key_length);
}
memcached_return_t memcached_set_encoding_key(memcached_st* shell, const char *key, size_t key_length)
{
- Memcached* self= memcached2Memcached(shell);
- if (self == NULL)
+ Memcached* memc= memcached2Memcached(shell);
+ if (memc)
{
- return MEMCACHED_INVALID_ARGUMENTS;
+ _set_encoding_key(*memc, key, key_length);
+ return MEMCACHED_SUCCESS;
}
- _set_encoding_key(*self, key, key_length);
- return MEMCACHED_SUCCESS;
+ return MEMCACHED_INVALID_ARGUMENTS;
}
extern "C" {
#endif
- memcached_string_t memcached_encoding_key(memcached_st&);
+ memcached_string_t memcached_encoding_key(Memcached&);
#ifdef __cplusplus
}
*
*/
-#include <libmemcached/common.h>
-#include <libmemcached/assert.hpp>
+#include "libmemcached/common.h"
+#include "libmemcached/assert.hpp"
-memcached_return_t memcached_set_namespace(memcached_st *self, const char *key, size_t key_length)
+memcached_return_t memcached_set_namespace(Memcached& memc, const char *key, size_t key_length)
{
- assert_msg(self, "A NULL memcached_st was used");
-
if (key and key_length == 0)
{
WATCHPOINT_ASSERT(key_length);
- return memcached_set_error(*self, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid namespace, namespace string had value but length was 0"));
+ return memcached_set_error(memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid namespace, namespace string had value but length was 0"));
}
else if (key_length and key == NULL)
{
WATCHPOINT_ASSERT(key);
- return memcached_set_error(*self, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid namespace, namespace string length was > 1 but namespace string was null "));
+ return memcached_set_error(memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid namespace, namespace string length was > 1 but namespace string was null "));
}
else if (key and key_length)
{
- bool orig= self->flags.verify_key;
- self->flags.verify_key= true;
- if (memcached_failed(memcached_key_test(*self, (const char **)&key, &key_length, 1)))
+ bool orig= memc.flags.verify_key;
+ memc.flags.verify_key= true;
+ if (memcached_failed(memcached_key_test(memc, (const char **)&key, &key_length, 1)))
{
- self->flags.verify_key= orig;
- return memcached_last_error(self);
+ memc.flags.verify_key= orig;
+ return memcached_last_error(&memc);
}
- self->flags.verify_key= orig;
+ memc.flags.verify_key= orig;
if ((key_length > MEMCACHED_PREFIX_KEY_MAX_SIZE -1))
{
- return memcached_set_error(*self, MEMCACHED_KEY_TOO_BIG, MEMCACHED_AT);
+ return memcached_set_error(memc, MEMCACHED_KEY_TOO_BIG, MEMCACHED_AT);
}
- memcached_array_free(self->_namespace);
- self->_namespace= memcached_strcpy(self, key, key_length);
+ memcached_array_free(memc._namespace);
+ memc._namespace= memcached_strcpy(&memc, key, key_length);
- if (not self->_namespace)
+ if (memc._namespace == NULL)
{
- return memcached_set_error(*self, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
+ return memcached_set_error(memc, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
}
}
else
{
- memcached_array_free(self->_namespace);
- self->_namespace= NULL;
+ memcached_array_free(memc._namespace);
+ memc._namespace= NULL;
}
return MEMCACHED_SUCCESS;
}
-const char * memcached_get_namespace(memcached_st *self)
+const char * memcached_get_namespace(Memcached& memc)
{
- if (self->_namespace == NULL)
+ if (memc._namespace == NULL)
{
return NULL;
}
- return memcached_array_string(self->_namespace);
+ return memcached_array_string(memc._namespace);
}
#pragma once
#ifdef __cplusplus
-extern "C" {
-#endif
-LIBMEMCACHED_LOCAL
- memcached_return_t memcached_set_namespace(memcached_st *self, const char *str, size_t length);
+memcached_return_t memcached_set_namespace(Memcached&, const char *str, size_t length);
-LIBMEMCACHED_LOCAL
- const char * memcached_get_namespace(memcached_st *self);
+const char * memcached_get_namespace(Memcached&);
-#ifdef __cplusplus
-}
-#endif
+#endif // __cplusplus
const uint32_t buckets,
const uint32_t replicas)
{
- if (! self || ! host_map || ! buckets)
+ if (self == NULL || host_map == NULL || buckets == 0U)
{
return MEMCACHED_INVALID_ARGUMENTS;
}
void memcached_virtual_bucket_free(memcached_st *self)
{
- if (self == NULL)
+ if (self)
{
- return;
- }
-
- if (self->virtual_bucket == NULL)
- {
- return;
+ if (self->virtual_bucket)
+ {
+ free(self->virtual_bucket);
+ self->virtual_bucket= NULL;
+ }
}
-
- free(self->virtual_bucket);
- self->virtual_bucket= NULL;
}
uint32_t memcached_virtual_bucket_get(const memcached_st *self, uint32_t digest)
{
- if (self == NULL)
+ if (self)
{
- return 0;
- }
-
- if (self->virtual_bucket == NULL)
- {
- return 0;
- }
+ if (self->virtual_bucket)
+ {
+ if (self->virtual_bucket)
+ {
+ uint32_t result= (uint32_t) (digest & (self->virtual_bucket->size -1));
+ return self->virtual_bucket->buckets[result].master;
+ }
- if (self->virtual_bucket)
- {
- uint32_t result= (uint32_t) (digest & (self->virtual_bucket->size -1));
- return self->virtual_bucket->buckets[result].master;
+ return (uint32_t) (digest & (self->number_of_hosts -1));
+ }
}
- return (uint32_t) (digest & (self->number_of_hosts -1));
+ return 0;
}
*
* Libmemcached library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
extern "C" {
#endif
-LIBMEMCACHED_LOCAL
memcached_return_t memcached_virtual_bucket_create(memcached_st *self,
const uint32_t *host_map,
const uint32_t *forward_map,
const uint32_t buckets,
const uint32_t replicas);
-LIBMEMCACHED_LOCAL
uint32_t memcached_virtual_bucket_get(const memcached_st *self, uint32_t digest);
-LIBMEMCACHED_LOCAL
void memcached_virtual_bucket_free(memcached_st *self);
#ifdef __cplusplus