Extended string structure for eventual static strings.
Added result structure.
typedef struct memcached_st memcached_st;
typedef struct memcached_stat_st memcached_stat_st;
+typedef struct memcached_result_st memcached_result_st;
typedef struct memcached_string_st memcached_string_st;
typedef struct memcached_server_st memcached_server_st;
};
struct memcached_string_st {
+ memcached_allocated is_allocated;
char *string;
char *end;
size_t current_size;
size_t block_size;
};
+struct memcached_result_st {
+ memcached_string_st key;
+ memcached_string_st result;
+ uint16_t flags;
+ uint64_t cas;
+};
+
struct memcached_st {
memcached_allocated is_allocated;
memcached_server_st *hosts;
unsigned long long flags;
int send_size;
int recv_size;
+ memcached_string_st result_buffer;
memcached_hash hash;
memcached_return warning; /* Future Use */
};
char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length,
size_t *value_length, uint16_t *flags,
memcached_return *error);
+memcached_result_st *memcached_fetch_object(memcached_st *ptr, memcached_return *error);
/* Server Public functions */
#define memcached_server_count(A) A->number_of_hosts
#define memcached_string_size(A, B) B->current_size
#define memcached_string_value(A, B) B->string
-memcached_string_st *memcached_string_create(memcached_st *ptr, size_t initial_size);
+memcached_string_st *memcached_string_create(memcached_st *ptr,
+ memcached_string_st *string,
+ size_t initial_size);
memcached_return memcached_string_append_character(memcached_st *ptr,
memcached_string_st *string,
char character);
*value_length= 0;
return NULL;
}
+
+#ifdef NOT_YET
+char *memcached_fetch_result(memcached_st *ptr, memcached_result_st *result,
+ memcached_return *error)
+{
+ char *value_check;
+
+ while (ptr->cursor_server < ptr->number_of_hosts)
+ {
+ if (!ptr->hosts[ptr->cursor_server].cursor_active)
+ {
+ ptr->cursor_server++;
+ continue;
+ }
+
+ value_check= memcached_value_fetch(ptr, key, key_length, value_length, flags,
+ error, 1, ptr->cursor_server);
+
+ if (*error == MEMCACHED_NOTFOUND)
+ ptr->cursor_server++;
+ else if (*error == MEMCACHED_END && *value_length == 0)
+ return NULL;
+ else if (*error == MEMCACHED_END)
+ {
+ WATCHPOINT_ASSERT(0); /* If this happens we have somehow messed up the fetch */
+ }
+ else if (*error != MEMCACHED_SUCCESS)
+ return NULL;
+ else
+ return value_check;
+
+ }
+
+ *value_length= 0;
+ return NULL;
+}
+#endif
static uint32_t FNV_32_PRIME= 16777619;
/* Prototypes */
-static unsigned int internal_generate_hash(char *key, size_t key_length);
-static uint32_t internal_generate_md5(char *key, size_t key_length);
-static uint32_t internal_generate_md5(char *key, size_t key_length);
-static uint32_t internal_generate_ketama_md5(char *key, size_t key_length);
+static uint64_t internal_generate_hash(char *key, size_t key_length);
+static uint64_t internal_generate_md5(char *key, size_t key_length);
+static uint64_t internal_generate_ketama_md5(char *key, size_t key_length);
unsigned int memcached_generate_hash(memcached_st *ptr, char *key, size_t key_length)
{
- uint32_t hash;
+ uint64_t hash= 1; /* Just here to remove compile warning */
unsigned int x;
switch (ptr->hash)
case MEMCACHED_HASH_FNV1_64:
{
/* Thanks to pierre@demartines.com for the pointer */
- hash = FNV_64_INIT;
+ hash= FNV_64_INIT;
for (x= 0; x < key_length; x++)
{
hash *= FNV_64_PRIME;
return hash % ptr->number_of_hosts;
}
-static uint32_t internal_generate_hash(char *key, size_t key_length)
+static uint64_t internal_generate_hash(char *key, size_t key_length)
{
char *ptr= key;
- unsigned int value= 0;
+ uint64_t value= 0;
while (--key_length)
{
return value == 0 ? 1 : value;
}
-static uint32_t internal_generate_md5(char *key, size_t key_length)
+static uint64_t internal_generate_md5(char *key, size_t key_length)
{
unsigned char results[16];
md5_signature((unsigned char*)key, (unsigned int)key_length, results);
- return (uint32_t)(( results[3] << 24 )
+ return (uint64_t)(( results[3] << 24 )
| ( results[2] << 16 )
| ( results[1] << 8 )
| results[0] );
}
-static uint32_t internal_generate_ketama_md5(char *key, size_t key_length)
+static uint64_t internal_generate_ketama_md5(char *key, size_t key_length)
{
unsigned char results[16];
return MEMCACHED_SUCCESS;
}
-memcached_string_st *memcached_string_create(memcached_st *ptr, size_t initial_size)
+memcached_string_st *memcached_string_create(memcached_st *ptr, memcached_string_st *string, size_t initial_size)
{
memcached_return rc;
- memcached_string_st *string;
/* Saving malloc calls :) */
- string= (memcached_string_st *)malloc(sizeof(memcached_string_st));
- if (!string)
- return NULL;
+ if (string)
+ {
+ memset(string, 0, sizeof(memcached_string_st));
+ string->is_allocated= MEMCACHED_NOT_ALLOCATED;
+ }
+ else
+ {
+ string= (memcached_string_st *)malloc(sizeof(memcached_string_st));
+ if (!string)
+ return NULL;
+ memset(string, 0, sizeof(memcached_string_st));
+ string->is_allocated= MEMCACHED_ALLOCATED;
+ }
string->end= string->string;
- memset(string, 0, sizeof(memcached_string_st));
string->block_size= initial_size;
rc= memcached_string_check(string, initial_size);
void memcached_string_free(memcached_st *ptr, memcached_string_st *string)
{
free(string->string);
- free(string);
+ if (string->is_allocated == MEMCACHED_ALLOCATED)
+ free(string);
}
free(keys);
}
+void string_static_null(memcached_st *memc)
+{
+ memcached_string_st string;
+ memcached_string_st *string_ptr;
+
+ string_ptr= memcached_string_create(memc, &string, 0);
+ assert(string.is_allocated == MEMCACHED_NOT_ALLOCATED);
+ assert(string_ptr);
+ memcached_string_free(memc, &string);
+}
+
void string_alloc_null(memcached_st *memc)
{
memcached_string_st *string;
- string= memcached_string_create(memc, 0);
+ string= memcached_string_create(memc, NULL, 0);
assert(string);
memcached_string_free(memc, string);
}
{
memcached_string_st *string;
- string= memcached_string_create(memc, 1024);
+ string= memcached_string_create(memc, NULL, 1024);
assert(string);
memcached_string_free(memc, string);
}
{
memcached_string_st *string;
- string= memcached_string_create(memc, INT64_MAX);
+ string= memcached_string_create(memc, NULL, INT64_MAX);
assert(string == NULL);
}
/* Ring the bell! */
memset(buffer, 6, SMALL_STRING_LEN);
- string= memcached_string_create(memc, 100);
+ string= memcached_string_create(memc, NULL, 100);
assert(string);
for (x= 0; x < 1024; x++)
/* Ring the bell! */
memset(buffer, 6, SMALL_STRING_LEN);
- string= memcached_string_create(memc, 100);
+ string= memcached_string_create(memc, NULL, 100);
assert(string);
for (x= 0; x < 1024; x++)
};
test_st string_tests[] ={
+ {"string static with null", 0, string_static_null },
{"string alloc with null", 0, string_alloc_null },
{"string alloc with 1K", 0, string_alloc_with_size },
{"string alloc with malloc failure", 0, string_alloc_with_size_toobig },