From: Brian Aker Date: Wed, 16 Dec 2009 17:52:31 +0000 (-0800) Subject: Additional flag removal. X-Git-Tag: 0.37~77 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=070f9452d0e14086ef7b6cf6fef4bf109f7d2cc5;p=awesomized%2Flibmemcached Additional flag removal. --- diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 512e768e..efc81edf 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -12,9 +12,11 @@ #include #include + #if !defined(__cplusplus) # include #endif + #include #include @@ -92,7 +94,25 @@ struct memcached_st { 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; diff --git a/libmemcached/memcached_auto.c b/libmemcached/memcached_auto.c index 207c4e51..b6355c15 100644 --- a/libmemcached/memcached_auto.c +++ b/libmemcached/memcached_auto.c @@ -11,12 +11,12 @@ static memcached_return memcached_auto(memcached_st *ptr, 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); @@ -69,7 +69,7 @@ static memcached_return binary_incr_decr(memcached_st *ptr, uint8_t cmd, 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; @@ -130,18 +130,22 @@ memcached_return memcached_increment_by_key(memcached_st *ptr, 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(); @@ -154,12 +158,12 @@ memcached_return memcached_decrement_by_key(memcached_st *ptr, 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, @@ -195,12 +199,12 @@ memcached_return memcached_increment_with_initial_by_key(memcached_st *ptr, 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, @@ -236,18 +240,22 @@ memcached_return memcached_decrement_with_initial_by_key(memcached_st *ptr, 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(); diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index 4f462f99..e434893f 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -10,14 +10,6 @@ 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) @@ -47,29 +39,32 @@ memcached_return memcached_behavior_set(memcached_st *ptr, 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: @@ -101,7 +96,7 @@ memcached_return memcached_behavior_set(memcached_st *ptr, { 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; } @@ -133,17 +128,17 @@ memcached_return memcached_behavior_set(memcached_st *ptr, 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; @@ -168,17 +163,17 @@ memcached_return memcached_behavior_set(memcached_st *ptr, 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 */ @@ -192,8 +187,6 @@ memcached_return memcached_behavior_set(memcached_st *ptr, 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: @@ -205,32 +198,24 @@ uint64_t memcached_behavior_get(memcached_st *ptr, 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: @@ -253,8 +238,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, 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: @@ -300,25 +284,18 @@ uint64_t memcached_behavior_get(memcached_st *ptr, 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; } diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index f3ee1481..67f76bc4 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -81,7 +81,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr) } #endif - if (ptr->root->flags & MEM_NO_BLOCK) + if (ptr->root->flags.no_block) { int error; struct linger linger; @@ -93,7 +93,7 @@ static memcached_return set_socket_options(memcached_server_st *ptr) WATCHPOINT_ASSERT(error == 0); } - if (ptr->root->flags & MEM_TCP_NODELAY) + if (ptr->root->flags.tcp_nodelay) { int flag= 1; int error; @@ -196,7 +196,7 @@ static memcached_return network_connect(memcached_server_st *ptr) struct addrinfo *use; if (!ptr->sockaddr_inited || - (!(ptr->root->flags & MEM_USE_CACHE_LOOKUPS))) + (!(ptr->root->flags.use_cache_lookups))) { memcached_return rc; diff --git a/libmemcached/memcached_delete.c b/libmemcached/memcached_delete.c index bba3c196..e2b77a54 100644 --- a/libmemcached/memcached_delete.c +++ b/libmemcached/memcached_delete.c @@ -28,7 +28,7 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, 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; @@ -36,10 +36,10 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, 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); @@ -93,7 +93,7 @@ memcached_return memcached_delete_by_key(memcached_st *ptr, 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; @@ -133,7 +133,7 @@ static inline memcached_return binary_delete(memcached_st *ptr, 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; @@ -141,7 +141,7 @@ static inline memcached_return binary_delete(memcached_st *ptr, 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) diff --git a/libmemcached/memcached_do.c b/libmemcached/memcached_do.c index 46ca79b9..db359534 100644 --- a/libmemcached/memcached_do.c +++ b/libmemcached/memcached_do.c @@ -27,7 +27,7 @@ memcached_return memcached_do(memcached_server_st *ptr, const void *command, 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; diff --git a/libmemcached/memcached_dump.c b/libmemcached/memcached_dump.c index 5872aa40..1f60bade 100644 --- a/libmemcached/memcached_dump.c +++ b/libmemcached/memcached_dump.c @@ -83,7 +83,7 @@ error: 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); diff --git a/libmemcached/memcached_fetch.c b/libmemcached/memcached_fetch.c index dc253ca2..bf97b0bd 100644 --- a/libmemcached/memcached_fetch.c +++ b/libmemcached/memcached_fetch.c @@ -8,7 +8,7 @@ char *memcached_fetch(memcached_st *ptr, char *key, size_t *key_length, { memcached_result_st *result_buffer= &ptr->result; - unlikely (ptr->flags & MEM_USE_UDP) + unlikely (ptr->flags.use_udp) { *error= MEMCACHED_NOT_SUPPORTED; return NULL; @@ -45,7 +45,7 @@ memcached_result_st *memcached_fetch_result(memcached_st *ptr, { memcached_server_st *server; - unlikely (ptr->flags & MEM_USE_UDP) + unlikely (ptr->flags.use_udp) { *error= MEMCACHED_NOT_SUPPORTED; return NULL; diff --git a/libmemcached/memcached_flush.c b/libmemcached/memcached_flush.c index 1011b3f1..fe737eed 100644 --- a/libmemcached/memcached_flush.c +++ b/libmemcached/memcached_flush.c @@ -10,7 +10,7 @@ memcached_return memcached_flush(memcached_st *ptr, time_t expiration) 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); @@ -31,7 +31,8 @@ static memcached_return memcached_flush_textual(memcached_st *ptr, 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", @@ -67,7 +68,7 @@ static memcached_return memcached_flush_binary(memcached_st *ptr, 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; diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index 9ba1388d..a3a56501 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -35,7 +35,7 @@ char *memcached_get_by_key(memcached_st *ptr, 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; @@ -139,7 +139,7 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr, 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(); @@ -151,12 +151,12 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr, 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; @@ -174,7 +174,7 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr, { 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])) @@ -182,11 +182,11 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr, } } - 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; @@ -301,7 +301,7 @@ memcached_return memcached_mget_execute_by_key(memcached_st *ptr, 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; @@ -360,7 +360,7 @@ static memcached_return simple_binary_mget(memcached_st *ptr, 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) diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index 959fc296..04eeb553 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -172,7 +172,7 @@ uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_ 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]; diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index d7f78dea..75c84fcf 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -43,7 +43,7 @@ memcached_return run_distribution(memcached_st *ptr) 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: @@ -326,9 +326,9 @@ memcached_return memcached_server_push(memcached_st *ptr, memcached_server_st *l 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); @@ -408,8 +408,8 @@ static memcached_return server_add(memcached_st *ptr, const char *hostname, { 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, diff --git a/libmemcached/memcached_io.c b/libmemcached/memcached_io.c index 693ce95c..c74e2cdf 100644 --- a/libmemcached/memcached_io.c +++ b/libmemcached/memcached_io.c @@ -43,7 +43,7 @@ static memcached_return io_wait(memcached_server_st *ptr, } 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); @@ -112,7 +112,7 @@ static bool process_input_buffer(memcached_server_st *ptr) ** 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 diff --git a/libmemcached/memcached_quit.c b/libmemcached/memcached_quit.c index 8ac76d48..ba306ccc 100644 --- a/libmemcached/memcached_quit.c +++ b/libmemcached/memcached_quit.c @@ -18,7 +18,7 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) 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; diff --git a/libmemcached/memcached_response.c b/libmemcached/memcached_response.c index fe13ddd5..81cb341a 100644 --- a/libmemcached/memcached_response.c +++ b/libmemcached/memcached_response.c @@ -25,7 +25,7 @@ memcached_return memcached_read_one_response(memcached_server_st *ptr, 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); @@ -44,7 +44,7 @@ memcached_return memcached_response(memcached_server_st *ptr, 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); /* @@ -52,7 +52,7 @@ memcached_return memcached_response(memcached_server_st *ptr, * 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); @@ -83,7 +83,7 @@ static memcached_return textual_value_fetch(memcached_server_st *ptr, 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); diff --git a/libmemcached/memcached_server.c b/libmemcached/memcached_server.c index ca0f4d04..03e76ac4 100644 --- a/libmemcached/memcached_server.c +++ b/libmemcached/memcached_server.c @@ -127,7 +127,7 @@ memcached_server_st *memcached_server_by_key(memcached_st *ptr, const char *key 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; @@ -137,7 +137,7 @@ memcached_server_st *memcached_server_by_key(memcached_st *ptr, const char *key 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; diff --git a/libmemcached/memcached_server.h b/libmemcached/memcached_server.h index 389f241d..cd110442 100644 --- a/libmemcached/memcached_server.h +++ b/libmemcached/memcached_server.h @@ -19,8 +19,8 @@ struct memcached_server_st { } 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 */ diff --git a/libmemcached/memcached_stats.c b/libmemcached/memcached_stats.c index f1defc5b..fc528fd9 100644 --- a/libmemcached/memcached_stats.c +++ b/libmemcached/memcached_stats.c @@ -361,7 +361,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur memcached_return rc; memcached_stat_st *stats; - unlikely (ptr->flags & MEM_USE_UDP) + unlikely (ptr->flags.use_udp) { *error= MEMCACHED_NOT_SUPPORTED; return NULL; @@ -380,7 +380,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur { 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); @@ -405,7 +405,7 @@ memcached_return memcached_stat_servername(memcached_stat_st *memc_stat, char *a 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); diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index ecefc566..4645aedb 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -72,25 +72,28 @@ static inline memcached_return memcached_send(memcached_st *ptr, 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), @@ -98,7 +101,8 @@ static inline memcached_return memcached_send(memcached_st *ptr, (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; @@ -122,10 +126,10 @@ static inline memcached_return memcached_send(memcached_st *ptr, "%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) @@ -152,10 +156,14 @@ static inline memcached_return memcached_send(memcached_st *ptr, 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) { @@ -163,7 +171,7 @@ static inline memcached_return memcached_send(memcached_st *ptr, goto error; } - if (ptr->flags & MEM_NOREPLY) + if (ptr->flags.no_reply) return (to_write == 0) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; if (to_write == 0) @@ -435,7 +443,7 @@ static memcached_return memcached_send_binary(memcached_st *ptr, 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); @@ -456,11 +464,12 @@ static memcached_return memcached_send_binary(memcached_st *ptr, 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) diff --git a/libmemcached/memcached_verbosity.c b/libmemcached/memcached_verbosity.c index fd56316d..f9bd928a 100644 --- a/libmemcached/memcached_verbosity.c +++ b/libmemcached/memcached_verbosity.c @@ -24,7 +24,7 @@ memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity) 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); diff --git a/libmemcached/memcached_version.c b/libmemcached/memcached_version.c index 9c070eaf..932e39f1 100644 --- a/libmemcached/memcached_version.c +++ b/libmemcached/memcached_version.c @@ -10,10 +10,10 @@ static inline memcached_return memcached_version_textual(memcached_st *ptr); 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); diff --git a/tests/function.c b/tests/function.c index 70a75557..a882ae8c 100644 --- a/tests/function.c +++ b/tests/function.c @@ -221,7 +221,25 @@ static test_return_t clone_test(memcached_st *memc) 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); @@ -3933,7 +3951,7 @@ static test_return_t dump_test(memcached_st *memc) 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); @@ -4371,6 +4389,7 @@ static test_return_t add_udp_server_tcp_client_test(memcached_st *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; } @@ -4381,15 +4400,16 @@ static test_return_t set_udp_behavior_test(memcached_st *memc) 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; }