test.c under behavior test.
typedef enum {
MEMCACHED_BEHAVIOR_NO_BLOCK,
- MEMCACHED_BEHAVIOR_BLOCK,
MEMCACHED_BEHAVIOR_TCP_NODELAY,
- MEMCACHED_BEHAVIOR_TCP_DELAY,
MEMCACHED_BEHAVIOR_MD5_HASHING,
} memcached_behavior;
void memcached_quit(memcached_st *ptr);
char *memcached_strerror(memcached_st *ptr, memcached_return rc);
memcached_return memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, void *data);
+unsigned long long memcached_behavior_get(memcached_st *ptr, memcached_behavior flag);
/* All of the functions for adding data to the server */
memcached_return memcached_set(memcached_st *ptr, char *key, size_t key_length,
#include "libmemcached_probes.h"
-#define MEM_NO_BLOCK (1 << 0)
-#define MEM_TCP_NODELAY (1 << 1)
-#define MEM_REUSE_MEMORY (1 << 2)
-#define MEM_USE_MD5 (1 << 3)
+typedef enum {
+ MEM_NO_BLOCK= (1 << 0),
+ MEM_TCP_NODELAY= (1 << 1),
+ MEM_REUSE_MEMORY= (1 << 2),
+ MEM_USE_MD5= (1 << 3),
+} memcached_flags;
void md5_signature(unsigned char *key, unsigned int length, unsigned char *result);
memcached_return memcached_connect(memcached_st *ptr);
#include <sys/socket.h>
#include <netinet/tcp.h>
+/*
+ This function is used to modify the behabior of running client.
+
+ We quit all connections so we can reset the sockets.
+*/
+
memcached_return memcached_behavior_set(memcached_st *ptr,
memcached_behavior flag,
void *data)
switch (flag)
{
case MEMCACHED_BEHAVIOR_NO_BLOCK:
- /* We quit all connections so we can reset the sockets */
- memcached_quit(ptr);
- ptr->flags|= MEM_NO_BLOCK;
- break;
- case MEMCACHED_BEHAVIOR_BLOCK:
- /* We quit all connections so we can reset the sockets */
- memcached_quit(ptr);
- ptr->flags+= MEM_NO_BLOCK;
- break;
+ {
+ unsigned int *truefalse= (unsigned int *)data;
+ memcached_quit(ptr);
+ if (truefalse)
+ ptr->flags|= MEM_NO_BLOCK;
+ else
+ ptr->flags+= MEM_NO_BLOCK;
+ break;
+ }
+
case MEMCACHED_BEHAVIOR_TCP_NODELAY:
- /* We quit all connections so we can reset the sockets */
- memcached_quit(ptr);
- ptr->flags|= MEM_TCP_NODELAY;
- break;
- case MEMCACHED_BEHAVIOR_TCP_DELAY:
- /* We quit all connections so we can reset the sockets */
- memcached_quit(ptr);
- ptr->flags+= MEM_TCP_NODELAY;
+ {
+ unsigned int *truefalse= (unsigned int *)data;
+ memcached_quit(ptr);
+ if (truefalse)
+ ptr->flags|= MEM_TCP_NODELAY;
+ else
+ ptr->flags+= MEM_TCP_NODELAY;
+ break;
+ }
+
case MEMCACHED_BEHAVIOR_MD5_HASHING:
ptr->flags+= MEM_USE_MD5;
break;
return MEMCACHED_SUCCESS;
}
+
+unsigned long long memcached_behavior_get(memcached_st *ptr,
+ memcached_behavior flag)
+{
+ switch (flag)
+ {
+ case MEMCACHED_BEHAVIOR_NO_BLOCK:
+ if (ptr->flags & MEM_NO_BLOCK)
+ return 1;
+ else
+ return 0;
+ case MEMCACHED_BEHAVIOR_TCP_NODELAY:
+ if (ptr->flags & MEM_TCP_NODELAY)
+ return 1;
+ else
+ return 0;
+ case MEMCACHED_BEHAVIOR_MD5_HASHING:
+ if (ptr->flags & MEM_USE_MD5)
+ return 1;
+ else
+ return 0;
+ }
+
+ return MEMCACHED_SUCCESS;
+}
{
if (ptr->hosts[x].fd != -1)
{
- char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
-
if (ptr->flags & MEM_NO_BLOCK)
memcached_io_write(ptr, x, "quit\r\n", 6, 1);
close(ptr->hosts[x].fd);
{
thread_context_st *context= (thread_context_st *)p;
memcached_st *memc;
+ unsigned int value= 1;
memc= memcached_create(NULL);
if (opt_non_blocking_io)
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, NULL );
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &value);
if (opt_tcp_nodelay)
- memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, NULL );
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &value);
memcached_server_push(memc, context->servers);
-servers localhost:5555,localhost
+servers localhost
Error 0 -> SUCCESS
Error 1 -> FAILURE
Error 2 -> HOSTNAME LOOKUP FAILURE
memcached_server_list_free(servers);
}
+/* We don't test the behavior itself, we test the switches */
+void behavior_test(memcached_st *memc)
+{
+ unsigned long long value;
+ unsigned int set= 1;
+
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
+ value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
+ assert(value == 1);
+
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
+ value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
+ assert(value == 1);
+
+ set= 0;
+
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, &set);
+ value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
+ assert(value == 0);
+
+ memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, &set);
+ value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY);
+ assert(value == 0);
+}
+
void add_host_test1(memcached_st *memc)
{
unsigned int x;
{"get_stats", 0, get_stats },
{"add_host_test", 0, add_host_test },
{"get_stats_keys", 0, get_stats_keys },
+ {"behavior_test", 0, get_stats_keys },
{0, 0, 0}
};