Clarrified the memcached_behavior_set will reconnect sockets.
All test cases pass.
memcached_behavior_set() changes the value of a particular option of the
client. It takes both a flag (listed below) and a value. For simple on or
-off options you just need to pass in a value of 1.
+off options you just need to pass in a value of 1. Calls to
+memcached_behavior_set() will flush and reset all connections.
=over 4
#define HUGE_STRING_LEN 8196
#define MEMCACHED_MAX_KEY 251 /* We add one to have it null terminated */
//#define MEMCACHED_MAX_BUFFER 8196
-#define MEMCACHED_MAX_BUFFER HUGE_STRING_LEN*4
+#define MEMCACHED_MAX_BUFFER HUGE_STRING_LEN*2
typedef enum {
MEMCACHED_SUCCESS,
MEMCACHED_BEHAVIOR_TCP_NODELAY,
MEMCACHED_BEHAVIOR_MD5_HASHING,
MEMCACHED_BEHAVIOR_KETAMA,
+ MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE,
+ MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE,
} memcached_behavior;
typedef enum {
char connected;
int my_errno;
unsigned long long flags;
+ int send_size;
+ int recv_size;
memcached_return warning; /* Future Use */
};
case MEMCACHED_BEHAVIOR_KETAMA:
set_behavior_flag(ptr, MEM_USE_KETAMA, data);
break;
+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
+ {
+ ptr->send_size= (*((int *)data));
+ memcached_quit(ptr);
+ break;
+ }
+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
+ {
+ ptr->recv_size= (*((int *)data));
+ memcached_quit(ptr);
+ break;
+ }
+
+
}
return MEMCACHED_SUCCESS;
unsigned long long memcached_behavior_get(memcached_st *ptr,
memcached_behavior flag)
{
- memcached_flags temp_flag;
+ memcached_flags temp_flag= 0;
switch (flag)
{
case MEMCACHED_BEHAVIOR_KETAMA:
temp_flag= MEM_USE_KETAMA;
break;
+ case MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE:
+ {
+ int sock_size;
+ socklen_t sock_length= sizeof(int);
+
+ /* We just try the first host, and if it is down we return zero */
+ if ((memcached_connect(ptr, 0)) != MEMCACHED_SUCCESS)
+ return 0;
+
+ if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
+ SO_SNDBUF, &sock_size, &sock_length))
+ return 0; /* Zero means error */
+
+ return sock_size;
+ }
+ case MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE:
+ {
+ int sock_size;
+ socklen_t sock_length= sizeof(int);
+
+ /* We just try the first host, and if it is down we return zero */
+ if ((memcached_connect(ptr, 0)) != MEMCACHED_SUCCESS)
+ return 0;
+
+ if (getsockopt(ptr->hosts[0].fd, SOL_SOCKET,
+ SO_RCVBUF, &sock_size, &sock_length))
+ return 0; /* Zero means error */
+
+ return sock_size;
+ }
}
+ assert(temp_flag); /* Programming mistake if it gets this far */
if (ptr->flags & temp_flag)
return 1;
else
return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
}
-
/* bind any port number */
localAddr.sin_family = AF_INET;
localAddr.sin_addr.s_addr = htonl(INADDR_ANY);
&flag, (socklen_t)sizeof(int));
}
+ if (ptr->send_size)
+ {
+ setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF,
+ &ptr->send_size, (socklen_t)sizeof(int));
+ }
+
+ if (ptr->recv_size)
+ {
+ setsockopt(ptr->hosts[server_key].fd, SOL_SOCKET, SO_SNDBUF,
+ &ptr->recv_size, (socklen_t)sizeof(int));
+ }
+
/* connect to server */
test_connect:
if (connect(ptr->hosts[server_key].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
servers localhost
+ localhost : 11211
+
Error 0 -> SUCCESS
Error 1 -> FAILURE
Error 2 -> HOSTNAME LOOKUP FAILURE
Error 22 -> SERVER DELETE
Error 23 -> SERVER VALUE
Error 24 -> STAT VALUE
+Error 25 -> UNKOWN ERROR SEE MY_ERRNO
Found key pid
Found key uptime
Found key time
Error 22 -> SERVER DELETE
Error 23 -> SERVER VALUE
Error 24 -> STAT VALUE
+Error 25 -> UNKOWN ERROR SEE MY_ERRNO
Found key pid
Found key uptime
Found key time
Error 22 -> SERVER DELETE
Error 23 -> SERVER VALUE
Error 24 -> STAT VALUE
+Error 25 -> UNKOWN ERROR SEE MY_ERRNO
Found key pid
Found key uptime
Found key time
Error 22 -> SERVER DELETE
Error 23 -> SERVER VALUE
Error 24 -> STAT VALUE
+Error 25 -> UNKOWN ERROR SEE MY_ERRNO
Found key pid
Found key uptime
Found key time
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_delete(memc, key, strlen(key), (time_t)0);
- WATCHPOINT_ERROR(rc);
assert(rc == MEMCACHED_SUCCESS);
}
string= memcached_get(memc, key, strlen(key),
&string_length, &flags, &rc);
- WATCHPOINT_ERRNO(memc->my_errno);
- WATCHPOINT_ERROR(rc);
assert(rc == MEMCACHED_SUCCESS);
assert(string);
assert(string_length == value_length);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_MD5_HASHING, &set);
value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_MD5_HASHING);
assert(value == 0);
+
+ value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_SEND_SIZE);
+ assert(value > 0);
+
+ value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SOCKET_RECV_SIZE);
+ assert(value > 0);
}
/* Test case provided by Cal Haldenbrand */