#define PROGRAM_DESCRIPTION "Copy a set of files to a memcached cluster."
/* Prototypes */
-void options_parse(int argc, char *argv[]);
+static void options_parse(int argc, char *argv[]);
static int opt_binary=0;
static int opt_verbose= 0;
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
(uint64_t)opt_binary);
- while (optind < argc)
+ while (optind < argc)
{
struct stat sbuf;
int fd;
else
ptr= argv[optind];
- if (opt_verbose)
+ if (opt_verbose)
{
static const char *opstr[] = { "set", "add", "replace" };
printf("op: %s\nsource file: %s\nlength: %zu\n"
if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL)
{
- fprintf(stderr, "malloc: %s\n", strerror(errno));
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
exit(1);
}
if ((read_length= read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1)
{
- fprintf(stderr, "read: %s\n", strerror(errno));
+ fprintf(stderr, "read: %s\n", strerror(errno));
exit(1);
}
if (rc != MEMCACHED_SUCCESS)
{
- fprintf(stderr, "memcp: %s: memcache error %s",
+ fprintf(stderr, "memcp: %s: memcache error %s",
ptr, memcached_strerror(memc, rc));
if (memc->cached_errno)
fprintf(stderr, " system error %s", strerror(memc->cached_errno));
return 0;
}
-void options_parse(int argc, char *argv[])
+static void options_parse(int argc, char *argv[])
{
int option_index= 0;
int option_rv;
{0, 0, 0, 0},
};
- while (1)
+ while (1)
{
option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
#define PROGRAM_DESCRIPTION "Dump all values from one or many servers."
/* Prototypes */
-void options_parse(int argc, char *argv[]);
+static void options_parse(int argc, char *argv[]);
static int opt_binary=0;
static int opt_verbose= 0;
static char *opt_hash= NULL;
/* Print the keys and counter how many were found */
-static memcached_return_t key_printer(memcached_st *ptr __attribute__((unused)),
- const char *key, size_t key_length,
+static memcached_return_t key_printer(memcached_st *ptr __attribute__((unused)),
+ const char *key, size_t key_length,
void *context __attribute__((unused)))
{
printf("%.*s\n", (uint32_t)key_length, key);
return 0;
}
-void options_parse(int argc, char *argv[])
+static void options_parse(int argc, char *argv[])
{
int option_index= 0;
int option_rv;
{0, 0, 0, 0}
};
- while (1)
+ while (1)
{
option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
#define PROGRAM_DESCRIPTION "Erase a key or set of keys from a memcached cluster."
/* Prototypes */
-void options_parse(int argc, char *argv[]);
+static void options_parse(int argc, char *argv[]);
int main(int argc, char *argv[])
{
memcached_server_list_free(servers);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
(uint64_t) opt_binary);
-
- while (optind < argc)
+
+ while (optind < argc)
{
- if (opt_verbose)
+ if (opt_verbose)
printf("key: %s\nexpires: %llu\n", argv[optind], (unsigned long long)opt_expire);
rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire);
- if (rc != MEMCACHED_SUCCESS)
+ if (rc != MEMCACHED_SUCCESS)
{
- fprintf(stderr, "memrm: %s: memcache error %s",
+ fprintf(stderr, "memrm: %s: memcache error %s",
argv[optind], memcached_strerror(memc, rc));
if (memc->cached_errno)
fprintf(stderr, " system error %s", strerror(memc->cached_errno));
}
-void options_parse(int argc, char *argv[])
+static void options_parse(int argc, char *argv[])
{
memcached_programs_help_st help_options[]=
{
int option_index= 0;
int option_rv;
- while (1)
+ while (1)
{
option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
if (option_rv == -1) break;
* Mingqiang Zhuang <mingqiangzhuang@hengtiansoft.com>
*
*/
+#include <stdlib.h>
#include <getopt.h>
#include <limits.h>
uint64_t total_get_cmds= 0, total_get_hits= 0;
uint32_t server_count, x;
memcached_analysis_st *result;
-
+
*error= MEMCACHED_SUCCESS;
server_count= memcached_server_count(memc);
result= (memcached_analysis_st*)calloc(memc->number_of_hosts,
calc_largest_consumption(result, x, memc_stat[x].bytes);
calc_oldest_node(result, x, memc_stat[x].uptime);
calc_least_free_node(result, x,
- memc_stat[x].limit_maxbytes,
+ memc_stat[x].limit_maxbytes,
memc_stat[x].bytes);
total_get_hits+= memc_stat[x].get_hits;
in_port_t port,
uint32_t weight,
memcached_connection_t type);
-memcached_return_t update_continuum(memcached_st *ptr);
+static memcached_return_t update_continuum(memcached_st *ptr);
static int compare_servers(const void *p1, const void *p2)
{
return -1;
}
-memcached_return_t update_continuum(memcached_st *ptr)
+static memcached_return_t update_continuum(memcached_st *ptr)
{
uint32_t host_index;
uint32_t continuum_index= 0;
if (list[host_index].port == MEMCACHED_DEFAULT_PORT)
{
sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
- "%s-%d",
+ "%s-%u",
list[host_index].hostname,
pointer_index - 1);
}
else
{
sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH,
- "%s:%d-%d",
+ "%s:%u-%u",
list[host_index].hostname,
- list[host_index].port, pointer_index - 1);
+ (uint32_t)list[host_index].port,
+ pointer_index - 1);
}
WATCHPOINT_ASSERT(sort_host_length);
memcached_st *memcached_create(memcached_st *ptr)
{
- memcached_result_st *result_ptr;
-
if (ptr == NULL)
{
ptr= (memcached_st *)calloc(1, sizeof(memcached_st));
memcached_set_memory_allocators(ptr, NULL, NULL, NULL, NULL);
- result_ptr= memcached_result_create(ptr, &ptr->result);
- WATCHPOINT_ASSERT(result_ptr);
+ if (! memcached_result_create(ptr, &ptr->result))
+ {
+ memcached_free(ptr);
+ return NULL;
+ }
ptr->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT;
ptr->connect_timeout= MEMCACHED_DEFAULT_TIMEOUT;
ptr->retry_timeout= 0;
uint64_t *value);
LIBMEMCACHED_API
-memcached_return_t memcached_increment_by_key(memcached_st *ptr,
+memcached_return_t memcached_increment_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
uint64_t offset,
uint64_t *value);
LIBMEMCACHED_API
-memcached_return_t memcached_decrement_by_key(memcached_st *ptr,
+memcached_return_t memcached_decrement_by_key(memcached_st *ptr,
const char *master_key, size_t master_key_length,
const char *key, size_t key_length,
uint64_t offset,
LIBMEMCACHED_API
memcached_return_t memcached_server_add_udp(memcached_st *ptr,
- const char *hostname,
- in_port_t port);
+ const char *hostname,
+ in_port_t port);
LIBMEMCACHED_API
memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr,
- const char *filename);
+ const char *filename);
LIBMEMCACHED_API
-memcached_return_t memcached_server_add(memcached_st *ptr,
+memcached_return_t memcached_server_add(memcached_st *ptr,
const char *hostname, in_port_t port);
LIBMEMCACHED_API
memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
- const char *hostname,
- in_port_t port,
- uint32_t weight);
+ const char *hostname,
+ in_port_t port,
+ uint32_t weight);
LIBMEMCACHED_API
memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr,
- const char *filename,
- uint32_t weight);
+ const char *filename,
+ uint32_t weight);
LIBMEMCACHED_API
memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname,
- in_port_t port,
- uint32_t weight);
+ in_port_t port,
+ uint32_t weight);
LIBMEMCACHED_API
void memcached_server_list_free(memcached_server_st *ptr);
rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), 1);
}
else
+ {
rc= memcached_do(ptr, "quit\r\n", 6, 1);
+ }
WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED);
+ (void)rc; // Shut up ICC
/* read until socket is closed, or there is an error
* closing the socket before all data is read
/* NOTREACHED */
}
-char *memcached_result_value(memcached_result_st *ptr)
-{
- memcached_string_st *sptr= &ptr->value;
- return memcached_string_value(sptr);
-}
-
-size_t memcached_result_length(memcached_result_st *ptr)
-{
- memcached_string_st *sptr= &ptr->value;
- return memcached_string_length(sptr);
-}
-
static memcached_return_t binary_read_one_response(memcached_server_st *ptr,
char *buffer, size_t buffer_length,
memcached_result_st *result)
ptr->options.is_initialized= false;
}
}
+
+
+char *memcached_result_value(memcached_result_st *ptr)
+{
+ memcached_string_st *sptr= &ptr->value;
+ return memcached_string_value(sptr);
+}
+
+size_t memcached_result_length(memcached_result_st *ptr)
+{
+ memcached_string_st *sptr= &ptr->value;
+ return memcached_string_length(sptr);
+}
+
#define memcached_result_value(A) memcached_string_value((A)->value)
#define memcached_result_length(A) memcached_string_length((A)->value)
#else
+
LIBMEMCACHED_API
char *memcached_result_value(memcached_result_st *ptr);
+
LIBMEMCACHED_API
size_t memcached_result_length(memcached_result_st *ptr);
+
#endif
#define memcached_result_flags(A) (A)->flags
#define memcached_result_cas(A) (A)->cas
}
memcached_return_t memcached_string_append_character(memcached_string_st *string,
- char character)
+ char character)
{
memcached_return_t rc;
}
memcached_return_t memcached_string_append(memcached_string_st *string,
- const char *value, size_t length)
+ const char *value, size_t length)
{
memcached_return_t rc;
}
#define READ_THROUGH_VALUE "set for me"
-static memcached_return_t read_through_trigger(memcached_st *memc __attribute__((unused)),
- char *key __attribute__((unused)),
- size_t key_length __attribute__((unused)),
- memcached_result_st *result)
+static memcached_return_t read_through_trigger(memcached_st *memc __attribute__((unused)),
+ char *key __attribute__((unused)),
+ size_t key_length __attribute__((unused)),
+ memcached_result_st *result)
{
return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
}
-static test_return_t read_through(memcached_st *memc)
+static test_return_t read_through(memcached_st *memc)
{
memcached_return_t rc;
const char *key= "foo";
&string_length, &flags, &rc);
test_truth(rc == MEMCACHED_NOTFOUND);
- test_truth(string_length == 0);
- test_truth(!string);
+ test_false(string_length);
+ test_false(string);
rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE,
*(void **)&cb);
test_truth(rc == MEMCACHED_SUCCESS);
test_truth(string_length == strlen(READ_THROUGH_VALUE));
- test_truth(!strcmp(READ_THROUGH_VALUE, string));
+ test_strcmp(READ_THROUGH_VALUE, string);
free(string);
string= memcached_get(memc, key, strlen(key),
&string_length, &flags, &rc);
test_truth(rc == MEMCACHED_NOTFOUND);
- test_truth(string_length == 0);
- test_truth(!string);
+ test_false(string_length);
+ test_false(string);
return TEST_SUCCESS;
}
memcached_return_t rc;
memcached_stat_st memc_stat;
rc= memcached_stat_servername(&memc_stat, NULL,
- memc->hosts[0].hostname,
- memc->hosts[0].port);
+ memc->hosts[0].hostname,
+ memc->hosts[0].port);
return TEST_SUCCESS;
}
test_truth(rc == MEMCACHED_SUCCESS);
for (ptr= stat_list; *ptr; ptr++)
test_truth(*ptr);
- fflush(stdout);
free(stat_list);