#include <stdlib.h>
#include <inttypes.h>
+
#if !defined(__cplusplus)
# include <stdbool.h>
#endif
+
#include <sys/types.h>
#include <netinet/in.h>
uint32_t number_of_hosts;
uint32_t cursor_server;
int cached_errno;
- uint32_t flags;
+ struct {
+ bool no_block:1;
+ bool tcp_nodelay:1;
+ bool reuse_memory:1;
+ bool use_md5:1;
+ bool use_crc:1;
+ bool use_cache_lookups:1;
+ bool support_cas:1;
+ bool buffer_requests:1;
+ bool use_sort_hosts:1;
+ bool verify_key:1;
+ bool ketama_weighted:1;
+ bool binary_protocol:1;
+ bool hash_with_prefix_key:1;
+ bool no_reply:1;
+ bool use_udp:1;
+ bool auto_eject_hosts:1;
+ bool randomize_replica_read:1;
+ } flags;
int32_t poll_timeout;
int32_t connect_timeout;
int32_t retry_timeout;
memcached_return rc;
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
- bool no_reply= (ptr->flags & MEM_NOREPLY);
+ bool no_reply= ptr->flags.no_reply;
unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
- if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
+ if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_BAD_KEY_PROVIDED;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
uint64_t *value)
{
unsigned int server_key;
- bool no_reply= (ptr->flags & MEM_NOREPLY);
+ bool no_reply= ptr->flags.no_reply;
unlikely (ptr->hosts == NULL || ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
uint64_t offset,
uint64_t *value)
{
- memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
LIBMEMCACHED_MEMCACHED_INCREMENT_START();
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
+ {
rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_INCREMENT,
master_key, master_key_length, key, key_length,
(uint64_t)offset, 0, MEMCACHED_EXPIRATION_NOT_ADD,
value);
+ }
else
+ {
rc= memcached_auto(ptr, "incr", master_key, master_key_length, key, key_length, offset, value);
+ }
LIBMEMCACHED_MEMCACHED_INCREMENT_END();
uint64_t offset,
uint64_t *value)
{
- memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
LIBMEMCACHED_MEMCACHED_DECREMENT_START();
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_DECREMENT,
master_key, master_key_length, key, key_length,
(uint64_t)offset, 0, MEMCACHED_EXPIRATION_NOT_ADD,
time_t expiration,
uint64_t *value)
{
- memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START();
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_INCREMENT,
master_key, master_key_length, key, key_length,
offset, initial, (uint32_t)expiration,
time_t expiration,
uint64_t *value)
{
- memcached_return rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
+ memcached_return rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_START();
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
+ {
rc= binary_incr_decr(ptr, PROTOCOL_BINARY_CMD_DECREMENT,
master_key, master_key_length, key, key_length,
offset, initial, (uint32_t)expiration,
value);
+ }
else
+ {
rc= MEMCACHED_PROTOCOL_ERROR;
+ }
LIBMEMCACHED_MEMCACHED_INCREMENT_WITH_INITIAL_END();
We quit all connections so we can reset the sockets.
*/
-static void set_behavior_flag(memcached_st *ptr, memcached_flags temp_flag, uint64_t data)
-{
- if (data)
- ptr->flags|= temp_flag;
- else
- ptr->flags&= ~temp_flag;
-}
-
memcached_return memcached_behavior_set(memcached_st *ptr,
memcached_behavior flag,
uint64_t data)
break;
case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL:
if (data)
- set_behavior_flag(ptr, MEM_VERIFY_KEY, 0);
- set_behavior_flag(ptr, MEM_BINARY_PROTOCOL, data);
+ ptr->flags.verify_key= false;
+
+ ptr->flags.binary_protocol= data ? true : false;
break;
case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
- set_behavior_flag(ptr, MEM_SUPPORT_CAS, data);
+ ptr->flags.support_cas= data ? true: false;
break;
case MEMCACHED_BEHAVIOR_NO_BLOCK:
- set_behavior_flag(ptr, MEM_NO_BLOCK, data);
+ ptr->flags.no_block= data ? true: false;
memcached_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
- set_behavior_flag(ptr, MEM_BUFFER_REQUESTS, data);
+ ptr->flags.buffer_requests= data ? true : false;
memcached_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_USE_UDP:
if (ptr->number_of_hosts)
return MEMCACHED_FAILURE;
- set_behavior_flag(ptr, MEM_USE_UDP, data);
+ ptr->flags.use_udp= data ? true : false;
+
if (data)
- set_behavior_flag(ptr,MEM_NOREPLY,data);
+ ptr->flags.no_reply= data ? true : false;
break;
+
case MEMCACHED_BEHAVIOR_TCP_NODELAY:
- set_behavior_flag(ptr, MEM_TCP_NODELAY, data);
+ ptr->flags.tcp_nodelay= data ? true : false;
memcached_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
{
ptr->hash= MEMCACHED_HASH_MD5;
ptr->distribution= MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA;
- set_behavior_flag(ptr, MEM_KETAMA_WEIGHTED, data);
+ ptr->flags.ketama_weighted= data ? true : false;
run_distribution(ptr);
break;
}
run_distribution(ptr);
break;
case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
- set_behavior_flag(ptr, MEM_USE_CACHE_LOOKUPS, data);
+ ptr->flags.use_cache_lookups= data ? true : false;
memcached_quit(ptr);
break;
case MEMCACHED_BEHAVIOR_VERIFY_KEY:
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
break;
- set_behavior_flag(ptr, MEM_VERIFY_KEY, data);
+ ptr->flags.verify_key= data ? true : false;
break;
case MEMCACHED_BEHAVIOR_SORT_HOSTS:
{
- set_behavior_flag(ptr, MEM_USE_SORT_HOSTS, data);
+ ptr->flags.use_sort_hosts= data ? true : false;
run_distribution(ptr);
break;
case MEMCACHED_BEHAVIOR_USER_DATA:
return MEMCACHED_FAILURE;
case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY:
- set_behavior_flag(ptr, MEM_HASH_WITH_PREFIX_KEY, data);
+ ptr->flags.hash_with_prefix_key= data ? true : false;
break;
case MEMCACHED_BEHAVIOR_NOREPLY:
- set_behavior_flag(ptr, MEM_NOREPLY, data);
+ ptr->flags.no_reply= data ? true : false;
break;
case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS:
- set_behavior_flag(ptr, MEM_AUTO_EJECT_HOSTS, data);
+ ptr->flags.auto_eject_hosts= data ? true : false;
break;
- case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ:
+ case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ:
srandom((uint32_t) time(NULL));
- set_behavior_flag(ptr, MEM_RANDOMIZE_REPLICA_READ, data);
+ ptr->flags.randomize_replica_read= data ? true : false;
break;
default:
/* Shouldn't get here */
uint64_t memcached_behavior_get(memcached_st *ptr,
memcached_behavior flag)
{
- memcached_flags temp_flag= MEM_NO_BLOCK;
-
switch (flag)
{
case MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS:
case MEMCACHED_BEHAVIOR_IO_KEY_PREFETCH:
return ptr->io_key_prefetch;
case MEMCACHED_BEHAVIOR_BINARY_PROTOCOL:
- temp_flag= MEM_BINARY_PROTOCOL;
- break;
+ return ptr->flags.binary_protocol;
case MEMCACHED_BEHAVIOR_SUPPORT_CAS:
- temp_flag= MEM_SUPPORT_CAS;
- break;
+ return ptr->flags.support_cas;
case MEMCACHED_BEHAVIOR_CACHE_LOOKUPS:
- temp_flag= MEM_USE_CACHE_LOOKUPS;
+ return ptr->flags.use_cache_lookups;
break;
case MEMCACHED_BEHAVIOR_NO_BLOCK:
- temp_flag= MEM_NO_BLOCK;
- break;
+ return ptr->flags.no_block;
case MEMCACHED_BEHAVIOR_BUFFER_REQUESTS:
- temp_flag= MEM_BUFFER_REQUESTS;
- break;
+ return ptr->flags.buffer_requests;
case MEMCACHED_BEHAVIOR_USE_UDP:
- temp_flag= MEM_USE_UDP;
- break;
+ return ptr->flags.use_udp;
case MEMCACHED_BEHAVIOR_TCP_NODELAY:
- temp_flag= MEM_TCP_NODELAY;
- break;
+ return ptr->flags.tcp_nodelay;
case MEMCACHED_BEHAVIOR_VERIFY_KEY:
- temp_flag= MEM_VERIFY_KEY;
- break;
+ return ptr->flags.verify_key;
case MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED:
- temp_flag= MEM_KETAMA_WEIGHTED;
- break;
+ return ptr->flags.ketama_weighted;
case MEMCACHED_BEHAVIOR_DISTRIBUTION:
return ptr->distribution;
case MEMCACHED_BEHAVIOR_KETAMA:
case MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT:
return ptr->server_failure_limit;
case MEMCACHED_BEHAVIOR_SORT_HOSTS:
- temp_flag= MEM_USE_SORT_HOSTS;
- break;
+ return ptr->flags.use_sort_hosts;
case MEMCACHED_BEHAVIOR_POLL_TIMEOUT:
return (uint64_t)ptr->poll_timeout;
case MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT:
case MEMCACHED_BEHAVIOR_USER_DATA:
return MEMCACHED_FAILURE;
case MEMCACHED_BEHAVIOR_HASH_WITH_PREFIX_KEY:
- temp_flag= MEM_HASH_WITH_PREFIX_KEY;
- break;
+ return ptr->flags.hash_with_prefix_key;
case MEMCACHED_BEHAVIOR_NOREPLY:
- temp_flag= MEM_NOREPLY;
- break;
+ return ptr->flags.no_reply;
case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS:
- temp_flag= MEM_AUTO_EJECT_HOSTS;
- break;
+ return ptr->flags.auto_eject_hosts;
case MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ:
- temp_flag= MEM_RANDOMIZE_REPLICA_READ;
- break;
+ return ptr->flags.randomize_replica_read;
default:
WATCHPOINT_ASSERT(flag);
break;
}
- WATCHPOINT_ASSERT(temp_flag); /* Programming mistake if it gets this far */
- if (ptr->flags & temp_flag)
- return 1;
- else
- return 0;
+ WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */
+ return 0;
}
}
#endif
- if (ptr->root->flags & MEM_NO_BLOCK)
+ if (ptr->root->flags.no_block)
{
int error;
struct linger linger;
WATCHPOINT_ASSERT(error == 0);
}
- if (ptr->root->flags & MEM_TCP_NODELAY)
+ if (ptr->root->flags.tcp_nodelay)
{
int flag= 1;
int error;
struct addrinfo *use;
if (!ptr->sockaddr_inited ||
- (!(ptr->root->flags & MEM_USE_CACHE_LOOKUPS)))
+ (!(ptr->root->flags.use_cache_lookups)))
{
memcached_return rc;
LIBMEMCACHED_MEMCACHED_DELETE_START();
rc= memcached_validate_key_length(key_length,
- ptr->flags & MEM_BINARY_PROTOCOL);
+ ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
return MEMCACHED_NO_SERVERS;
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
- to_write= (uint8_t)((ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1);
- bool no_reply= (ptr->flags & MEM_NOREPLY);
+ to_write= (uint8_t)((ptr->flags.buffer_requests) ? 0 : 1);
+ bool no_reply= (ptr->flags.no_reply);
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
{
likely (!expiration)
rc= binary_delete(ptr, server_key, key, key_length, to_write);
goto error;
}
- if (ptr->flags & MEM_USE_UDP && !to_write)
+ if (ptr->flags.use_udp && !to_write)
{
if (send_length > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
return MEMCACHED_WRITE_FAILURE;
protocol_binary_request_delete request= {.bytes= {0}};
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
- if (ptr->flags & MEM_NOREPLY)
+ if (ptr->flags.no_reply)
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETEQ;
else
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_DELETE;
request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
request.message.header.request.bodylen= htonl((uint32_t) key_length);
- if (ptr->flags & MEM_USE_UDP && !flush)
+ if (ptr->flags.use_udp && !flush)
{
size_t cmd_size= sizeof(request.bytes) + key_length;
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
if (sent_length == -1 || (size_t)sent_length != command_length)
rc= MEMCACHED_WRITE_FAILURE;
- else if ((ptr->root->flags & MEM_NOREPLY) == 0)
+ else if ((ptr->root->flags.no_reply) == 0)
memcached_server_response_increment(ptr);
return rc;
memcached_return memcached_dump(memcached_st *ptr, memcached_dump_func *callback, void *context, uint32_t number_of_callbacks)
{
/* No support for Binary protocol yet */
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
return MEMCACHED_FAILURE;
return ascii_dump(ptr, callback, context, number_of_callbacks);
{
memcached_result_st *result_buffer= &ptr->result;
- unlikely (ptr->flags & MEM_USE_UDP)
+ unlikely (ptr->flags.use_udp)
{
*error= MEMCACHED_NOT_SUPPORTED;
return NULL;
{
memcached_server_st *server;
- unlikely (ptr->flags & MEM_USE_UDP)
+ unlikely (ptr->flags.use_udp)
{
*error= MEMCACHED_NOT_SUPPORTED;
return NULL;
memcached_return rc;
LIBMEMCACHED_MEMCACHED_FLUSH_START();
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
rc= memcached_flush_binary(ptr, expiration);
else
rc= memcached_flush_textual(ptr, expiration);
for (x= 0; x < ptr->number_of_hosts; x++)
{
- bool no_reply= (ptr->flags & MEM_NOREPLY);
+ bool no_reply= ptr->flags.no_reply;
+
if (expiration)
send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"flush_all %llu%s\r\n",
for (x= 0; x < ptr->number_of_hosts; x++)
{
- if (ptr->flags & MEM_NOREPLY)
+ if (ptr->flags.no_reply)
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSHQ;
else
request.message.header.request.opcode= PROTOCOL_BINARY_CMD_FLUSH;
uint32_t dummy_flags;
memcached_return dummy_error;
- unlikely (ptr->flags & MEM_USE_UDP)
+ unlikely (ptr->flags.use_udp)
{
*error= MEMCACHED_NOT_SUPPORTED;
return NULL;
unsigned int master_server_key= (unsigned int)-1; /* 0 is a valid server id! */
bool is_master_key_set= false;
- unlikely (ptr->flags & MEM_USE_UDP)
+ unlikely (ptr->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
LIBMEMCACHED_MEMCACHED_MGET_START();
if (ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
- if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
+ if (ptr->flags.verify_key && (memcached_key_test(keys, key_length, number_of_keys) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_BAD_KEY_PROVIDED;
if (master_key && master_key_length)
{
- if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char * const *)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
+ if (ptr->flags.verify_key && (memcached_key_test((const char * const *)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_BAD_KEY_PROVIDED;
master_server_key= memcached_generate_hash(ptr, master_key, master_key_length);
is_master_key_set= true;
{
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
- if (ptr->flags & MEM_NO_BLOCK)
+ if (ptr->flags.no_block)
(void)memcached_io_write(&ptr->hosts[x], NULL, 0, 1);
while(memcached_server_response_count(&ptr->hosts[x]))
}
}
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
return binary_mget_by_key(ptr, master_server_key, is_master_key_set, keys,
key_length, number_of_keys, mget_mode);
- if (ptr->flags & MEM_SUPPORT_CAS)
+ if (ptr->flags.support_cas)
{
get_command= "gets ";
get_command_length= 5;
void *context,
unsigned int number_of_callbacks)
{
- if ((ptr->flags & MEM_BINARY_PROTOCOL) == 0)
+ if ((ptr->flags.binary_protocol) == 0)
return MEMCACHED_NOT_SUPPORTED;
memcached_return rc;
memcached_return vk;
vk= memcached_validate_key_length(key_length[x],
- ptr->flags & MEM_BINARY_PROTOCOL);
+ ptr->flags.binary_protocol);
unlikely (vk != MEMCACHED_SUCCESS)
{
if (x > 0)
if (ptr->number_of_hosts == 1)
return 0;
- if (ptr->flags & MEM_HASH_WITH_PREFIX_KEY)
+ if (ptr->flags.hash_with_prefix_key)
{
size_t temp_length= ptr->prefix_key_length + key_length;
char temp[temp_length];
case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY:
return update_continuum(ptr);
case MEMCACHED_DISTRIBUTION_MODULA:
- if (ptr->flags & MEM_USE_SORT_HOSTS)
+ if (ptr->flags.use_sort_hosts)
sort_hosts(ptr);
break;
case MEMCACHED_DISTRIBUTION_RANDOM:
for (x= 0; x < count; x++)
{
- if ((ptr->flags & MEM_USE_UDP && list[x].type != MEMCACHED_CONNECTION_UDP)
+ if ((ptr->flags.use_udp && list[x].type != MEMCACHED_CONNECTION_UDP)
|| ((list[x].type == MEMCACHED_CONNECTION_UDP)
- && ! (ptr->flags & MEM_USE_UDP)) )
+ && ! (ptr->flags.use_udp)) )
return MEMCACHED_INVALID_HOST_PROTOCOL;
WATCHPOINT_ASSERT(list[x].hostname[0] != 0);
{
memcached_server_st *new_host_list;
- if ( (ptr->flags & MEM_USE_UDP && type != MEMCACHED_CONNECTION_UDP)
- || ( (type == MEMCACHED_CONNECTION_UDP) && !(ptr->flags & MEM_USE_UDP) ) )
+ if ( (ptr->flags.use_udp && type != MEMCACHED_CONNECTION_UDP)
+ || ( (type == MEMCACHED_CONNECTION_UDP) && (! ptr->flags.use_udp) ) )
return MEMCACHED_INVALID_HOST_PROTOCOL;
new_host_list= ptr->call_realloc(ptr, ptr->hosts,
}
int timeout= ptr->root->poll_timeout;
- if ((ptr->root->flags & MEM_NO_BLOCK) == 0)
+ if (ptr->root->flags.no_block == false)
timeout= -1;
error= poll(&fds, 1, timeout);
** We might be able to process some of the response messages if we
** have a callback set up
*/
- if (ptr->root->callbacks != NULL && (ptr->root->flags & MEM_USE_UDP) == 0)
+ if (ptr->root->callbacks != NULL && ptr->root->flags.use_udp == false)
{
/*
* We might have responses... try to read them out and fire
memcached_return rc;
char buffer[MEMCACHED_MAX_BUFFER];
- if (ptr->root->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->root->flags.binary_protocol)
{
protocol_binary_request_quit request = {.bytes= {0}};
request.message.header.request.magic = PROTOCOL_BINARY_REQ;
result = &ptr->root->result;
memcached_return rc;
- if (ptr->root->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->root->flags.binary_protocol)
rc= binary_read_one_response(ptr, buffer, buffer_length, result);
else
rc= textual_read_one_response(ptr, buffer, buffer_length, result);
memcached_result_st *result)
{
/* We may have old commands in the buffer not set, first purge */
- if (ptr->root->flags & MEM_NO_BLOCK)
+ if (ptr->root->flags.no_block)
(void)memcached_io_write(ptr, NULL, 0, 1);
/*
* returned the last one. Purge all pending messages to ensure backwards
* compatibility.
*/
- if ((ptr->root->flags & MEM_BINARY_PROTOCOL) == 0)
+ if (ptr->root->flags.binary_protocol == false)
while (memcached_server_response_count(ptr) > 1)
{
memcached_return rc= memcached_read_one_response(ptr, buffer, buffer_length, result);
size_t to_read;
char *value_ptr;
- if (ptr->root->flags & MEM_USE_UDP)
+ if (ptr->root->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
WATCHPOINT_ASSERT(ptr->root);
uint32_t server_key;
*error= memcached_validate_key_length(key_length,
- ptr->flags & MEM_BINARY_PROTOCOL);
+ ptr->flags.binary_protocol);
unlikely (*error != MEMCACHED_SUCCESS)
return NULL;
return NULL;
}
- if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
+ if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
{
*error= MEMCACHED_BAD_KEY_PROVIDED;
return NULL;
} options;
bool sockaddr_inited;
uint16_t count;
- unsigned int cursor_active;
- unsigned int port;
+ uint32_t cursor_active;
+ in_port_t port;
int cached_errno;
int fd;
uint32_t io_bytes_sent; /* # bytes sent since last read */
memcached_return rc;
memcached_stat_st *stats;
- unlikely (ptr->flags & MEM_USE_UDP)
+ unlikely (ptr->flags.use_udp)
{
*error= MEMCACHED_NOT_SUPPORTED;
return NULL;
{
memcached_return temp_return;
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
temp_return= binary_stats_fetch(ptr, stats + x, args, x);
else
temp_return= ascii_stats_fetch(ptr, stats + x, args, x);
memcached_server_add(&memc, hostname, port);
- if (memc.flags & MEM_BINARY_PROTOCOL)
+ if (memc.flags.binary_protocol)
rc= binary_stats_fetch(&memc, memc_stat, args, 0);
else
rc= ascii_stats_fetch(&memc, memc_stat, args, 0);
WATCHPOINT_ASSERT(!(value == NULL && value_length > 0));
- rc= memcached_validate_key_length(key_length, ptr->flags & MEM_BINARY_PROTOCOL);
+ rc= memcached_validate_key_length(key_length, ptr->flags.binary_protocol);
unlikely (rc != MEMCACHED_SUCCESS)
return rc;
unlikely (ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
- if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
+ if (ptr->flags.verify_key && (memcached_key_test((const char **)&key, &key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED))
return MEMCACHED_BAD_KEY_PROVIDED;
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
+ {
return memcached_send_binary(ptr, master_key, master_key_length,
key, key_length,
value, value_length, expiration,
flags, cas, verb);
+ }
server_key= memcached_generate_hash(ptr, master_key, master_key_length);
if (cas)
+ {
write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%s %s%.*s %u %llu %zu %llu%s\r\n",
storage_op_string(verb),
(int)key_length, key, flags,
(unsigned long long)expiration, value_length,
(unsigned long long)cas,
- (ptr->flags & MEM_NOREPLY) ? " noreply" : "");
+ (ptr->flags.no_reply) ? " noreply" : "");
+ }
else
{
char *buffer_ptr= buffer;
"%u %llu %zu%s\r\n",
flags,
(unsigned long long)expiration, value_length,
- (ptr->flags & MEM_NOREPLY) ? " noreply" : "");
+ ptr->flags.no_reply ? " noreply" : "");
}
- if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS)
+ if (ptr->flags.use_udp && ptr->flags.buffer_requests)
{
size_t cmd_size= write_length + value_length + 2;
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
goto error;
}
- if ((ptr->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP)
+ if (ptr->flags.buffer_requests && verb == SET_OP)
+ {
to_write= 0;
+ }
else
+ {
to_write= 1;
+ }
if ((sent_length= memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write)) == -1)
{
goto error;
}
- if (ptr->flags & MEM_NOREPLY)
+ if (ptr->flags.no_reply)
return (to_write == 0) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS;
if (to_write == 0)
uint32_t server_key= memcached_generate_hash(ptr, master_key,
master_key_length);
memcached_server_st *server= &ptr->hosts[server_key];
- bool noreply= server->root->flags & MEM_NOREPLY;
+ bool noreply= server->root->flags.no_reply;
request.message.header.request.magic= PROTOCOL_BINARY_REQ;
request.message.header.request.opcode= get_com_code(verb, noreply);
if (cas)
request.message.header.request.cas= htonll(cas);
- flush= (uint8_t) (((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1);
+ flush= (uint8_t) ((server->root->flags.buffer_requests && verb == SET_OP) ? 0 : 1);
- if ((server->root->flags & MEM_USE_UDP) && !flush)
+ if (server->root->flags.use_udp && !flush)
{
size_t cmd_size= send_length + key_length + value_length;
+
if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH)
return MEMCACHED_WRITE_FAILURE;
if (cmd_size + server->write_buffer_offset > MAX_UDP_DATAGRAM_LENGTH)
continue;
}
- unlikely (ptr->flags & MEM_USE_UDP)
+ unlikely (ptr->flags.use_udp)
continue;
rrc= memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
memcached_return memcached_version(memcached_st *ptr)
{
- if (ptr->flags & MEM_USE_UDP)
+ if (ptr->flags.use_udp)
return MEMCACHED_NOT_SUPPORTED;
- if (ptr->flags & MEM_BINARY_PROTOCOL)
+ if (ptr->flags.binary_protocol)
return memcached_version_binary(ptr);
else
return memcached_version_textual(ptr);
test_truth(memc_clone->connect_timeout == memc->connect_timeout);
test_truth(memc_clone->delete_trigger == memc->delete_trigger);
test_truth(memc_clone->distribution == memc->distribution);
- test_truth(memc_clone->flags == memc->flags);
+ { // Test all of the flags
+ test_truth(memc_clone->flags.no_block == memc->flags.no_block);
+ test_truth(memc_clone->flags.tcp_nodelay == memc->flags.tcp_nodelay);
+ test_truth(memc_clone->flags.reuse_memory == memc->flags.reuse_memory);
+ test_truth(memc_clone->flags.use_md5 == memc->flags.use_md5);
+ test_truth(memc_clone->flags.use_crc == memc->flags.use_crc);
+ test_truth(memc_clone->flags.use_cache_lookups == memc->flags.use_cache_lookups);
+ test_truth(memc_clone->flags.support_cas == memc->flags.support_cas);
+ test_truth(memc_clone->flags.buffer_requests == memc->flags.buffer_requests);
+ test_truth(memc_clone->flags.use_sort_hosts == memc->flags.use_sort_hosts);
+ test_truth(memc_clone->flags.verify_key == memc->flags.verify_key);
+ test_truth(memc_clone->flags.ketama_weighted == memc->flags.ketama_weighted);
+ test_truth(memc_clone->flags.binary_protocol == memc->flags.binary_protocol);
+ test_truth(memc_clone->flags.hash_with_prefix_key == memc->flags.hash_with_prefix_key);
+ test_truth(memc_clone->flags.no_reply == memc->flags.no_reply);
+ test_truth(memc_clone->flags.use_udp == memc->flags.use_udp);
+ test_truth(memc_clone->flags.auto_eject_hosts == memc->flags.auto_eject_hosts);
+ test_truth(memc_clone->flags.randomize_replica_read == memc->flags.randomize_replica_read);
+ }
test_truth(memc_clone->get_key_failure == memc->get_key_failure);
test_truth(memc_clone->hash == memc->hash);
test_truth(memc_clone->hash_continuum == memc->hash_continuum);
callbacks[0]= &callback_dump_counter;
/* No support for Binary protocol yet */
- if (memc->flags & MEM_BINARY_PROTOCOL)
+ if (memc->flags.binary_protocol)
return TEST_SUCCESS;
main_rc= set_test3(memc);
memcached_st tcp_client;
memcached_create(&tcp_client);
test_truth(memcached_server_add_udp(&tcp_client, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
+
return TEST_SUCCESS;
}
memc->number_of_hosts= 0;
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, memc->distribution);
test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1) == MEMCACHED_SUCCESS);
- test_truth(memc->flags & MEM_USE_UDP);
- test_truth(memc->flags & MEM_NOREPLY);;
+ test_truth(memc->flags.use_udp);
+ test_truth(memc->flags.no_reply);
test_truth(memc->number_of_hosts == 0);
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP,0);
- test_truth(!(memc->flags & MEM_USE_UDP));
+ test_truth(! (memc->flags.use_udp));
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY,0);
- test_truth(!(memc->flags & MEM_NOREPLY));
+ test_truth(! (memc->flags.no_reply));
+
return TEST_SUCCESS;
}