-Brian Aker, brian@mysql.com | brian@tangent.org
+Brian Aker, brian@tangent.org -- Client Library, Tools
+Mark Atwood, -- Tools
test: all\r
cd tests; make test; cd ..\r
\r
-ltest: all \r
- ./tests/testapp output.txt\r
+test-extended: all\r
+ cd tests; make test-extended; cd ..\r
\r
valgrind:\r
cd tests; make valgrind; cd ..\r
\r
+valgrind-extended:\r
+ cd tests; make valgrind-extended; cd ..\r
+\r
\r
typedef struct memcached_st memcached_st;
typedef struct memcached_stat_st memcached_stat_st;
typedef struct memcached_string_st memcached_string_st;
-typedef struct memcached_host_st memcached_host_st;
+typedef struct memcached_server_st memcached_server_st;
#define MEMCACHED_DEFAULT_PORT 11211
#define MEMCACHED_DEFAULT_COMMAND_SIZE 350
#define HUGE_STRING_LEN 8196
#define MEMCACHED_MAX_KEY 251 /* We add one to have it null terminated */
-#define WATCHPOINT printf("WATCHPOINT %s:%d\n", __FILE__, __LINE__);fflush(stdout);
-
typedef enum {
MEMCACHED_SUCCESS,
MEMCACHED_FAILURE,
MEMCACHED_MEMORY_ALLOCATION_FAILURE,
MEMCACHED_PARTIAL_READ,
MEMCACHED_SOME_ERRORS,
+ MEMCACHED_NO_SERVERS,
+ MEMCACHED_MAXIMUM_RETURN, /* Always add new error code before */
} memcached_return;
typedef enum {
MEMCACHED_ALLOCATED= 1,
} memcached_allocated;
-struct memcached_host_st {
+struct memcached_server_st {
char *hostname;
unsigned int port;
int fd;
struct memcached_st {
memcached_allocated is_allocated;
- memcached_host_st *hosts;
+ memcached_server_st *hosts;
unsigned int number_of_hosts;
unsigned int cursor_server;
char connected;
memcached_st *memcached_init(memcached_st *ptr);
void memcached_deinit(memcached_st *ptr);
-memcached_return memcached_set(memcached_st *ptr, char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags);
-memcached_return memcached_add(memcached_st *ptr, char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags);
-memcached_return memcached_replace(memcached_st *ptr, char *key, size_t key_length,
- char *value, size_t value_length,
- time_t expiration,
- uint16_t flags);
memcached_return memcached_delete(memcached_st *ptr, char *key, size_t key_length,
time_t expiration);
memcached_return memcached_increment(memcached_st *ptr,
unsigned int offset,
unsigned int *value);
memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_return *error);
-memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
- char *hostname, unsigned int port);
+memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args,
+ char *hostname, unsigned int port);
memcached_return memcached_flush(memcached_st *ptr, time_t expiration);
memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity);
void memcached_quit(memcached_st *ptr);
+char *memcached_strerror(memcached_st *ptr, memcached_return rc);
+
+/* All of the functions for adding data to the server */
+memcached_return memcached_set(memcached_st *ptr, char *key, size_t key_length,
+ char *value, size_t value_length,
+ time_t expiration,
+ uint16_t flags);
+memcached_return memcached_add(memcached_st *ptr, char *key, size_t key_length,
+ char *value, size_t value_length,
+ time_t expiration,
+ uint16_t flags);
+memcached_return memcached_replace(memcached_st *ptr, char *key, size_t key_length,
+ char *value, size_t value_length,
+ time_t expiration,
+ uint16_t flags);
+
+/* Get functions */
char *memcached_get(memcached_st *ptr, char *key, size_t key_length,
size_t *value_length,
uint16_t *flags,
char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length,
size_t *value_length, uint16_t *flags,
memcached_return *error);
+
+/* Server Public functions */
+#define memcached_server_count(A) A->number_of_hosts
+#define memcached_server_name(A,B) B.hostname
+#define memcached_server_port(A,B) B.port
+#define memcached_server_list(A) A->hosts
+
memcached_return memcached_server_add(memcached_st *ptr, char *hostname,
unsigned int port);
-char *memcached_strerror(memcached_st *ptr, memcached_return rc);
/* These are all private, do not use. */
memcached_return memcached_connect(memcached_st *ptr);
char *buffer, size_t buffer_length,
unsigned int server_key);
unsigned int memcached_generate_hash(char *key, size_t key_length);
-memcached_return memcached_stat_get_value(memcached_stat_st *stat, char *key,
- char *value, size_t value_length);
-char ** memcached_stat_get_keys(memcached_stat_st *stat, memcached_return *error);
+char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat,
+ char *key, memcached_return *error);
+char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat,
+ memcached_return *error);
+
/* String Struct */
#define memcached_string_length(A, B) (size_t)(B->end - B->string)
memcached_return memcached_string_reset(memcached_st *ptr, memcached_string_st *string);
void memcached_string_free(memcached_st *ptr, memcached_string_st *string);
+/* Some personal debugging functions */
+#define WATCHPOINT printf("WATCHPOINT %s:%d\n", __FILE__, __LINE__);fflush(stdout);
+#define WATCHPOINT_ERROR(A) printf("WATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout);
+
+
#ifdef __cplusplus
}
#endif
memcached_return memcached_server_add(memcached_st *ptr, char *hostname, unsigned int port)
{
- memcached_host_st *new_host_list;
+ memcached_server_st *new_host_list;
char *new_hostname;
if (!port)
hostname= "localhost";
- new_host_list= (memcached_host_st *)realloc(ptr->hosts, sizeof(memcached_host_st) * (ptr->number_of_hosts+1));
+ new_host_list= (memcached_server_st *)realloc(ptr->hosts, sizeof(memcached_server_st) * (ptr->number_of_hosts+1));
if (!new_host_list)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- memset(&new_host_list[ptr->number_of_hosts], 0, sizeof(memcached_host_st));
+ memset(&new_host_list[ptr->number_of_hosts], 0, sizeof(memcached_server_st));
if (!new_host_list)
return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
struct sockaddr_in localAddr, servAddr;
struct hostent *h;
- if (ptr->connected)
+ if (ptr->connected == ptr->number_of_hosts)
return MEMCACHED_SUCCESS;
if (!ptr->hosts)
{
- memcached_return rc;
- rc= memcached_server_add(ptr, NULL, 0);
-
- if (rc != MEMCACHED_SUCCESS)
- return rc;
+ return MEMCACHED_NO_SERVERS;
}
-
for (x= 0; x < ptr->number_of_hosts; x++)
{
- if ((h= gethostbyname(ptr->hosts[x].hostname)) == NULL)
- return MEMCACHED_HOST_LOCKUP_FAILURE;
+ if (ptr->hosts[x].fd == -1)
+ {
+ if ((h= gethostbyname(ptr->hosts[x].hostname)) == NULL)
+ return MEMCACHED_HOST_LOCKUP_FAILURE;
- servAddr.sin_family= h->h_addrtype;
- memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
- servAddr.sin_port = htons(ptr->hosts[x].port);
+ servAddr.sin_family= h->h_addrtype;
+ memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
+ servAddr.sin_port = htons(ptr->hosts[x].port);
- /* Create the socket */
- if ((ptr->hosts[0].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0)
- return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
+ /* Create the socket */
+ if ((ptr->hosts[0].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
- /* bind any port number */
- localAddr.sin_family = AF_INET;
- localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
- localAddr.sin_port = htons(0);
+ /* bind any port number */
+ localAddr.sin_family = AF_INET;
+ localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ localAddr.sin_port = htons(0);
- if (bind(ptr->hosts[0].fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0)
- return(MEMCACHED_CONNECTION_BIND_FAILURE);
+ if (bind(ptr->hosts[0].fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0)
+ return(MEMCACHED_CONNECTION_BIND_FAILURE);
- /* connect to server */
- if (connect(ptr->hosts[0].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
- return MEMCACHED_HOST_LOCKUP_FAILURE;
- }
+ /* connect to server */
+ if (connect(ptr->hosts[0].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
+ return MEMCACHED_HOST_LOCKUP_FAILURE;
- ptr->connected= 1;
+ ptr->connected++;
+ }
+ }
return MEMCACHED_SUCCESS;
}
{
memcached_string_st *string= memcached_string_init(ptr, SMALL_STRING_LEN);
+ /* We need to figure out the correct way to error in case of this failure */
if (!string)
assert(0);
if (*error == MEMCACHED_NOTFOUND)
ptr->cursor_server++;
+ else if (*error != MEMCACHED_SUCCESS)
+ return NULL;
else
return value_check;
}
{
for (x= 0; x < ptr->number_of_hosts; x++)
{
- if (ptr->hosts[x].fd > 0)
+ if (ptr->hosts[x].fd != -1)
+ {
close(ptr->hosts[x].fd);
+ ptr->hosts[x].fd= -1;
+ }
}
}
+
ptr->connected= 0;
}
}
}
-memcached_return memcached_stat_get_value(memcached_stat_st *stat, char *key,
- char *value, size_t value_length)
+char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat,
+ char *key, memcached_return *error)
{
- memcached_return rc;
+ char buffer[SMALL_STRING_LEN];
+ *error= MEMCACHED_SUCCESS;
- rc= MEMCACHED_SUCCESS;
+
+ memset(buffer, 0, SMALL_STRING_LEN);
if (!memcmp("pid", key, strlen("pid")))
- {
- snprintf(value, value_length,"%u", stat->pid);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->pid);
else if (!memcmp("uptime", key, strlen("uptime")))
- {
- snprintf(value, value_length,"%u", stat->uptime);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->uptime);
else if (!memcmp("time", key, strlen("time")))
- {
- snprintf(value, value_length,"%llu", (unsigned long long)stat->time);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->time);
else if (!memcmp("version", key, strlen("version")))
- {
- snprintf(value, value_length,"%s", stat->version);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%s", stat->version);
else if (!memcmp("pointer_size", key, strlen("pointer_size")))
- {
- snprintf(value, value_length,"%u", stat->pointer_size);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->pointer_size);
else if (!memcmp("rusage_user", key, strlen("rusage_user")))
- {
- snprintf(value, value_length,"%u", stat->rusage_user);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->rusage_user);
else if (!memcmp("rusage_system", key, strlen("rusage_system")))
- {
- snprintf(value, value_length,"%u", stat->rusage_system);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->rusage_system);
else if (!memcmp("rusage_user_seconds", key, strlen("rusage_user_seconds")))
- {
- snprintf(value, value_length,"%u", stat->rusage_user_seconds);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->rusage_user_seconds);
else if (!memcmp("rusage_user_microseconds", key, strlen("rusage_user_microseconds")))
- {
- snprintf(value, value_length,"%u", stat->rusage_user_microseconds);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->rusage_user_microseconds);
else if (!memcmp("rusage_system_seconds", key, strlen("rusage_system_seconds")))
- {
- snprintf(value, value_length,"%u", stat->rusage_system_seconds);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->rusage_system_seconds);
else if (!memcmp("rusage_system_microseconds", key, strlen("rusage_system_microseconds")))
- {
- snprintf(value, value_length,"%u", stat->rusage_system_microseconds);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->rusage_system_microseconds);
else if (!memcmp("curr_items", key, strlen("curr_items")))
- {
- snprintf(value, value_length,"%u", stat->curr_items);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->curr_items);
else if (!memcmp("total_items", key, strlen("total_items")))
- {
- snprintf(value, value_length,"%u", stat->total_items);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->total_items);
else if (!memcmp("bytes", key, strlen("bytes")))
- {
- snprintf(value, value_length,"%llu", stat->bytes);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->bytes);
else if (!memcmp("curr_connections", key, strlen("curr_connections")))
- {
- snprintf(value, value_length,"%u", stat->curr_connections);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->curr_connections);
else if (!memcmp("total_connections", key, strlen("total_connections")))
- {
- snprintf(value, value_length,"%u", stat->total_connections);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->total_connections);
else if (!memcmp("connection_structures", key, strlen("connection_structures")))
- {
- snprintf(value, value_length,"%u", stat->connection_structures);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->connection_structures);
else if (!memcmp("cmd_get", key, strlen("cmd_get")))
- {
- snprintf(value, value_length,"%llu", stat->cmd_get);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->cmd_get);
else if (!memcmp("cmd_set", key, strlen("cmd_set")))
- {
- snprintf(value, value_length,"%llu", stat->cmd_set);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->cmd_set);
else if (!memcmp("get_hits", key, strlen("get_hits")))
- {
- snprintf(value, value_length,"%llu", stat->get_hits);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->get_hits);
else if (!memcmp("get_misses", key, strlen("get_misses")))
- {
- snprintf(value, value_length,"%llu", stat->get_misses);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->get_misses);
else if (!memcmp("evictions", key, strlen("evictions")))
- {
- snprintf(value, value_length,"%llu", stat->evictions);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->evictions);
else if (!memcmp("bytes_read", key, strlen("bytes_read")))
- {
- snprintf(value, value_length,"%llu", stat->bytes_read);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->bytes_read);
else if (!memcmp("bytes_written", key, strlen("bytes_written")))
- {
- snprintf(value, value_length,"%llu", stat->bytes_written);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%llu", stat->bytes_written);
else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes")))
- {
- snprintf(value, value_length,"%u", stat->limit_maxbytes);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->limit_maxbytes);
else if (!memcmp("threads", key, strlen("threads")))
- {
- snprintf(value, value_length,"%u", stat->threads);
- }
+ snprintf(buffer, SMALL_STRING_LEN,"%u", stat->threads);
else
{
- rc= MEMCACHED_NOTFOUND;
+ *error= MEMCACHED_NOTFOUND;
+ return NULL;
}
- return rc;
+ return strdup(buffer);
}
static memcached_return memcached_stats_fetch(memcached_st *ptr,
unsigned int x;
memcached_return rc;
memcached_stat_st *stats;
- rc= memcached_connect(ptr);
+ rc= memcached_connect(ptr);
if (rc != MEMCACHED_SUCCESS)
{
*error= rc;
}
stats= (memcached_stat_st *)malloc(sizeof(memcached_st)*(ptr->number_of_hosts+1));
- if (stats)
+ if (!stats)
{
*error= MEMCACHED_MEMORY_ALLOCATION_FAILURE;
+ free(stats);
return NULL;
}
memset(stats, 0, sizeof(memcached_st)*(ptr->number_of_hosts+1));
rc= MEMCACHED_SOME_ERRORS;
}
- *error= x == 0 ? MEMCACHED_SUCCESS : rc;
+ *error= rc;
return stats;
}
-memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
- char *hostname, unsigned int port)
+memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args,
+ char *hostname, unsigned int port)
{
memcached_return rc;
memcached_st memc;
We make a copy of the keys since at some point in the not so distant future
we will add support for "found" keys.
*/
-char ** memcached_stat_get_keys(memcached_stat_st *stat, memcached_return *error)
+char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat,
+ memcached_return *error)
{
char **list= (char **)malloc(sizeof(memcached_stat_keys));
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
- rc= memcached_connect(ptr);
assert(value);
assert(value_length);
+ rc= memcached_connect(ptr);
if (rc != MEMCACHED_SUCCESS)
return rc;
return "PARTIAL READ";
case MEMCACHED_SOME_ERRORS:
return "SOME ERRORS WERE REPORTED";
+ case MEMCACHED_NO_SERVERS:
+ return "NO SERVERS DEFINED";
+ case MEMCACHED_MAXIMUM_RETURN:
+ return "Gibberish returned!";
+ default:
+ return "Gibberish returned!";
};
return "COMPLETELY UNKNOWN ERROR, SOMEONE FORGOT TO UPDATE ERROR MESSAGES";
fprintf(stderr, "memcp: %s: memcache error %s\n", \r
ptr, memcached_strerror(memc, rc));\r
\r
- WATCHPOINT;\r
free(file_buffer_ptr);\r
close(fd);\r
optind++;\r
/* Prototypes */
void options_parse(int argc, char *argv[]);
-static int opt_verbose;
-static int opt_displayflag;
-static char *opt_servers;
+static int opt_verbose= 0;
+static int opt_displayflag= 0;
+static char *opt_servers= NULL;
int main(int argc, char *argv[])
{
options_parse(argc, argv);
if (opt_servers)
+ {
+ unsigned int x;
+ memcached_return rc;
+ memcached_stat_st *stat;
+ memcached_server_st *server_list;
+
parse_opt_servers(memc, opt_servers);
+ stat= memcached_stat(memc, NULL, &rc);
+
+ server_list= memcached_server_list(memc);
+
+ printf("Listing %u Server\n\n", memcached_server_count(memc));
+ for (x= 0; x < memcached_server_count(memc); x++)
+ {
+ char **list;
+ char **ptr;
+
+ list= memcached_stat_get_keys(memc, &stat[x], &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]),
+ memcached_server_port(memc, server_list[x]));
+ for (ptr= list; *ptr; ptr++)
+ {
+ memcached_return rc;
+ char *value= memcached_stat_get_value(memc, &stat[x], *ptr, &rc);
+
+ printf("\t %s: %s\n", *ptr, value);
+ free(value);
+ }
+
+ free(list);
+ printf("\n");
+ }
+
+ free(stat);
+ free(opt_servers);
+ }
memcached_deinit(memc);
exit(0);
break;
case OPT_SERVERS: /* --servers or -s */
- opt_servers= optarg;
+ opt_servers= strdup(optarg);
break;
case '?':
/* getopt_long already printed an error message. */
char *begin_ptr;
char *end_ptr;
- end_ptr= server_strings + strlen(server_strings);
-
assert(server_strings);
assert(memc);
+ end_ptr= server_strings + strlen(server_strings);
+
for (begin_ptr= server_strings, string= index(server_strings, ',');
- begin_ptr == end_ptr;
- begin_ptr= ++string, string= index(begin_ptr, ','))
+ begin_ptr != end_ptr;
+ string= index(begin_ptr, ','))
{
char buffer[HUGE_STRING_LEN];
char *ptr;
+ port= 0;
memset(buffer, 0, HUGE_STRING_LEN);
if (string)
{
memcpy(buffer, begin_ptr, string - begin_ptr);
+ begin_ptr= string+1;
}
else
{
size_t length= strlen(server_strings);
memcpy(buffer, begin_ptr, length);
string= server_strings+length;
+ begin_ptr= end_ptr;
}
ptr= index(buffer, ':');
ptr++;
port= strtol(ptr, (char **)NULL, 10);
-
- memcached_server_add(memc, buffer, port);
- }
- else
- {
- memcached_server_add(memc, buffer, 0);
}
+
+ memcached_server_add(memc, buffer, port);
}
}
testapp_LDADD = $(LDADDS)\r
\r
record:\r
- ./testapp output.txt > output.res\r
+ ./testapp > output.res\r
+\r
+record-extended:\r
+ ./testapp extended > output2.res\r
+\r
test: testapp\r
- ./testapp output.txt > output.cmp\r
+ ./testapp > output.cmp\r
diff output.res output.cmp\r
\r
+test-extended: testapp\r
+ ./testapp extended > output.cmp\r
+ diff output2.res output.cmp\r
+\r
valgrind:\r
- libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp output.txt\r
+ libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp\r
+\r
+valgrind-extended:\r
+ libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp extended\r
+Error 0 -> SUCCESS
+Error 1 -> FAILURE
+Error 2 -> HOSTNAME LOOKUP FAILURE
+Error 3 -> CONNECTION FAILURE
+Error 4 -> CONNECTION BIND FAILURE
+Error 5 -> WRITE FAILURE
+Error 6 -> READ FAILURE
+Error 7 -> UNKNOWN READ FAILURE
+Error 8 -> PROTOCOL ERROR
+Error 9 -> CLIENT ERROR
+Error 10 -> SERVER ERROR
+Error 11 -> CONNECTION SOCKET CREATE FAILURE
+Error 12 -> CONNECTION DATA EXISTS
+Error 13 -> CONNECTION DATA DOES NOT EXIST
+Error 14 -> NOT STORED
+Error 15 -> NOT FOUND
+Error 16 -> MEMORY ALLOCATION FAILURE
+Error 17 -> PARTIAL READ
+Error 18 -> SOME ERRORS WERE REPORTED
+Error 19 -> NO SERVERS DEFINED
+Found key pid
+Found key uptime
+Found key time
+Found key version
+Found key pointer_size
+Found key rusage_user
+Found key rusage_system
+Found key rusage_user_seconds
+Found key rusage_user_microseconds
+Found key rusage_system_seconds
+Found key rusage_system_microseconds
+Found key curr_items
+Found key total_items
+Found key bytes
+Found key curr_connections
+Found key total_connections
+Found key connection_structures
+Found key cmd_get
+Found key cmd_set
+Found key get_hits
+Found key get_misses
+Found key evictions
+Found key bytes_read
+Found key bytes_written
+Found key limit_maxbytes
+Found key threads
Found key pid
Found key uptime
Found key time
--- /dev/null
+Error 0 -> SUCCESS
+Error 1 -> FAILURE
+Error 2 -> HOSTNAME LOOKUP FAILURE
+Error 3 -> CONNECTION FAILURE
+Error 4 -> CONNECTION BIND FAILURE
+Error 5 -> WRITE FAILURE
+Error 6 -> READ FAILURE
+Error 7 -> UNKNOWN READ FAILURE
+Error 8 -> PROTOCOL ERROR
+Error 9 -> CLIENT ERROR
+Error 10 -> SERVER ERROR
+Error 11 -> CONNECTION SOCKET CREATE FAILURE
+Error 12 -> CONNECTION DATA EXISTS
+Error 13 -> CONNECTION DATA DOES NOT EXIST
+Error 14 -> NOT STORED
+Error 15 -> NOT FOUND
+Error 16 -> MEMORY ALLOCATION FAILURE
+Error 17 -> PARTIAL READ
+Error 18 -> SOME ERRORS WERE REPORTED
+Error 19 -> NO SERVERS DEFINED
+Found key pid
+Found key uptime
+Found key time
+Found key version
+Found key pointer_size
+Found key rusage_user
+Found key rusage_system
+Found key rusage_user_seconds
+Found key rusage_user_microseconds
+Found key rusage_system_seconds
+Found key rusage_system_microseconds
+Found key curr_items
+Found key total_items
+Found key bytes
+Found key curr_connections
+Found key total_connections
+Found key connection_structures
+Found key cmd_get
+Found key cmd_set
+Found key get_hits
+Found key get_misses
+Found key evictions
+Found key bytes_read
+Found key bytes_written
+Found key limit_maxbytes
+Found key threads
memcached_return rc;
memcached_st *memc;
memc= memcached_init(NULL);
+ assert(memc);
rc= memcached_server_add(memc, "localhost", 0);
assert(rc == MEMCACHED_SUCCESS);
assert(memc);
memcached_deinit(memc);
}
+void error_test(void)
+{
+ memcached_st *memc;
+ memc= memcached_init(NULL);
+ memcached_return rc;
+
+ for (rc= MEMCACHED_SUCCESS; rc < MEMCACHED_MAXIMUM_RETURN; rc++)
+ {
+ printf("Error %d -> %s\n", rc, memcached_strerror(memc, rc));
+ }
+
+ assert(memc);
+ memcached_deinit(memc);
+}
+
void set_test(void)
{
memcached_st *memc;
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
rc= memcached_add(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
rc= memcached_replace(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
rc= memcached_flush(memc, 0);
assert(rc == MEMCACHED_SUCCESS);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
string= memcached_get(memc, key, strlen(key),
&string_length, &flags, &rc);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
rc= memcached_set(memc, key, strlen(key),
value, value_length,
(time_t)0, (uint16_t)0);
memcached_deinit(memc);
}
-void stats_hostname_test(void)
+void stats_servername_test(void)
{
memcached_return rc;
memcached_stat_st stat;
- rc= memcached_stat_hostname(&stat, NULL,
- "localhost",
- MEMCACHED_DEFAULT_PORT);
+ rc= memcached_stat_servername(&stat, NULL,
+ "localhost",
+ MEMCACHED_DEFAULT_PORT);
}
void increment_test(void)
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
(time_t)0, (uint16_t)0);
memc= memcached_init(NULL);
assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
(time_t)10, (uint16_t)3);
memc= memcached_init(NULL);
assert(memc);
-
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ /* We need to empty the server before continueing test */
+ rc= memcached_flush(memc, 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
rc= memcached_mget(memc, keys, key_length, 3);
assert(rc == MEMCACHED_SUCCESS);
- while (return_value= memcached_fetch(memc, return_key, &return_key_length,
- &return_value_length, &flags, &rc))
+ while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
+ &return_value_length, &flags, &rc)) != NULL)
{
assert(return_value);
}
+ assert(!return_value);
assert(return_value_length == 0);
assert(rc == MEMCACHED_NOTFOUND);
{
char **list;
char **ptr;
+ memcached_st *memc;
memcached_stat_st stat;
memcached_return rc;
- list= memcached_stat_get_keys(&stat, &rc);
+ memc= memcached_init(NULL);
+ assert(memc);
+
+ list= memcached_stat_get_keys(memc, &stat, &rc);
assert(rc == MEMCACHED_SUCCESS);
for (ptr= list; *ptr; ptr++)
printf("Found key %s\n", *ptr);
free(list);
+ memcached_deinit(memc);
+}
+
+void get_stats(void)
+{
+ unsigned int x;
+ char **list;
+ char **ptr;
+ memcached_return rc;
+ memcached_st *memc;
+ memcached_stat_st *stat;
+
+ memc= memcached_init(NULL);
+ assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ stat= memcached_stat(memc, NULL, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(stat);
+
+ for (x= 0; x < memcached_server_count(memc); x++)
+ {
+ list= memcached_stat_get_keys(memc, &stat[x], &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+ for (ptr= list; *ptr; ptr++)
+ printf("Found key %s\n", *ptr);
+ free(list);
+ }
+
+ free(stat);
+ memcached_deinit(memc);
+}
+
+void get_stats_multiple(void)
+{
+ unsigned int x;
+ char **list;
+ char **ptr;
+ memcached_return rc;
+ memcached_st *memc;
+ memcached_stat_st *stat;
+
+ memc= memcached_init(NULL);
+ assert(memc);
+ rc= memcached_server_add(memc, "localhost", 0);
+ assert(rc == MEMCACHED_SUCCESS);
+ rc= memcached_server_add(memc, "localhost", 5555);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ stat= memcached_stat(memc, NULL, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(stat);
+
+ for (x= 0; x < memcached_server_count(memc); x++)
+ {
+ list= memcached_stat_get_keys(memc, &stat[x], &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+ for (ptr= list; *ptr; ptr++)
+ printf("Found key %s\n", *ptr);
+
+ free(list);
+ }
+
+ free(stat);
+ memcached_deinit(memc);
}
-int main(void)
+int main(int argc, char argvp[])
{
/* Clean the server before beginning testing */
flush_test();
init_test();
allocation_test();
connection_test();
+ error_test();
set_test();
add_test();
replace_test();
get_test();
get_test2();
get_test3();
- stats_hostname_test();
+ stats_servername_test();
increment_test();
decrement_test();
quit_test();
-// mget_test();
+ mget_test();
+ get_stats();
+
+ /* The multiple tests */
+ if (argc == 2)
+ {
+ get_stats_multiple();
+ }
get_stats_keys();
/* Clean up whatever we might have left */