From: Brian Aker Date: Fri, 22 Jan 2010 00:15:24 +0000 (-0800) Subject: Bool fix. X-Git-Tag: 0.40~64 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=857ca43d65fe6a52474641130312d26d125bef15;p=awesomized%2Flibmemcached Bool fix. --- diff --git a/libmemcached/auto.c b/libmemcached/auto.c index ba7ea6d3..608324df 100644 --- a/libmemcached/auto.c +++ b/libmemcached/auto.c @@ -43,7 +43,7 @@ static memcached_return_t text_incr_decr(memcached_st *ptr, unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - rc= memcached_do(instance, buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, true); if (no_reply || rc != MEMCACHED_SUCCESS) return rc; @@ -112,7 +112,7 @@ static memcached_return_t binary_incr_decr(memcached_st *ptr, uint8_t cmd, request.message.body.expiration= htonl((uint32_t) expiration); if ((memcached_do(instance, request.bytes, - sizeof(request.bytes), 0)!=MEMCACHED_SUCCESS) || + sizeof(request.bytes), false) != MEMCACHED_SUCCESS) || (memcached_io_write(instance, key, key_length, true) == -1)) { memcached_io_reset(instance); diff --git a/libmemcached/common.h b/libmemcached/common.h index c1cd0d8d..719a3a94 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -57,6 +57,7 @@ typedef struct memcached_server_st memcached_server_instance_st; /* These are private not to be installed headers */ +#include "libmemcached/do.h" #include "libmemcached/io.h" #include "libmemcached/internal.h" #include "libmemcached/libmemcached_probes.h" @@ -122,9 +123,6 @@ memcached_return_t run_distribution(memcached_st *ptr); #define memcached_set_allocated(__object, __value) ((__object)->options.is_allocated(= (__value)) -LIBMEMCACHED_LOCAL -memcached_return_t memcached_do(memcached_server_instance_st *ptr, const void *commmand, - size_t command_length, uint8_t with_flush); LIBMEMCACHED_LOCAL memcached_return_t value_fetch(memcached_server_instance_st *ptr, char *buffer, diff --git a/libmemcached/delete.c b/libmemcached/delete.c index 3109c9e6..75a44ed8 100644 --- a/libmemcached/delete.c +++ b/libmemcached/delete.c @@ -12,14 +12,14 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, uint32_t server_key, const char *key, size_t key_length, - uint8_t flush); + bool flush); memcached_return_t memcached_delete_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, time_t expiration) { - uint8_t to_write; + bool to_write; size_t send_length; memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -39,7 +39,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, server_key= memcached_generate_hash(ptr, master_key, master_key_length); instance= memcached_server_instance_fetch(ptr, server_key); - to_write= (uint8_t)((ptr->flags.buffer_requests) ? 0 : 1); + to_write= (ptr->flags.buffer_requests) ? false : true; bool no_reply= (ptr->flags.no_reply); @@ -77,13 +77,13 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, if (instance->minor_version == 0) { - if (no_reply || !to_write) + if (no_reply || ! to_write) { /* We might get out of sync with the server if we * send this command to a server newer than 1.2.x.. * disable no_reply and buffered mode. */ - to_write= 1; + to_write= true; if (no_reply) memcached_server_response_increment(instance); no_reply= false; @@ -111,7 +111,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, goto error; } - if (ptr->flags.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; @@ -125,7 +125,7 @@ memcached_return_t memcached_delete_by_key(memcached_st *ptr, if (rc != MEMCACHED_SUCCESS) goto error; - if (!to_write) + if (! to_write) rc= MEMCACHED_BUFFERED; else if (!no_reply) { @@ -146,7 +146,7 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, uint32_t server_key, const char *key, size_t key_length, - uint8_t flush) + bool flush) { memcached_server_instance_st *instance; protocol_binary_request_delete request= {.bytes= {0}}; @@ -162,7 +162,7 @@ static inline memcached_return_t 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.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) @@ -174,9 +174,9 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, memcached_return_t rc= MEMCACHED_SUCCESS; if ((memcached_do(instance, request.bytes, - sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) || + sizeof(request.bytes), false) != MEMCACHED_SUCCESS) || (memcached_io_write(instance, key, - key_length, (bool) flush) == -1)) + key_length, flush) == -1)) { memcached_io_reset(instance); rc= MEMCACHED_WRITE_FAILURE; @@ -197,8 +197,8 @@ static inline memcached_return_t binary_delete(memcached_st *ptr, replica= memcached_server_instance_fetch(ptr, server_key); if ((memcached_do(replica, (const char*)request.bytes, - sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) || - (memcached_io_write(replica, key, key_length, (bool) flush) == -1)) + sizeof(request.bytes), false) != MEMCACHED_SUCCESS) || + (memcached_io_write(replica, key, key_length, flush) == -1)) { memcached_io_reset(replica); } diff --git a/libmemcached/do.c b/libmemcached/do.c index fa33f51e..31d45840 100644 --- a/libmemcached/do.c +++ b/libmemcached/do.c @@ -1,7 +1,7 @@ #include "common.h" memcached_return_t memcached_do(memcached_server_st *ptr, const void *command, - size_t command_length, uint8_t with_flush) + size_t command_length, bool with_flush) { memcached_return_t rc; ssize_t sent_length; @@ -23,7 +23,7 @@ memcached_return_t memcached_do(memcached_server_st *ptr, const void *command, if (ptr->type == MEMCACHED_CONNECTION_UDP && with_flush && ptr->write_buffer_offset > UDP_DATAGRAM_HEADER_LENGTH) memcached_io_write(ptr, NULL, 0, true); - sent_length= memcached_io_write(ptr, command, command_length, (bool) with_flush); + sent_length= memcached_io_write(ptr, command, command_length, with_flush); if (sent_length == -1 || (size_t)sent_length != command_length) rc= MEMCACHED_WRITE_FAILURE; diff --git a/libmemcached/do.h b/libmemcached/do.h new file mode 100644 index 00000000..223ed832 --- /dev/null +++ b/libmemcached/do.h @@ -0,0 +1,27 @@ +/* LibMemcached + * Copyright (C) 2006-2009 Brian Aker + * All rights reserved. + * + * Use and distribution licensed under the BSD license. See + * the COPYING file in the parent directory for full text. + * + * Summary: Internal functions used by the library. Not for public use! + * + */ + +#ifndef __LIBMEMCACHED_DO_H__ +#define __LIBMEMCACHED_DO_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +LIBMEMCACHED_LOCAL +memcached_return_t memcached_do(memcached_server_instance_st *ptr, const void *commmand, + size_t command_length, bool with_flush); + +#ifdef __cplusplus +} +#endif + +#endif /* __LIBMEMCACHED_DO_H__ */ diff --git a/libmemcached/dump.c b/libmemcached/dump.c index 0e556e61..8d9c525f 100644 --- a/libmemcached/dump.c +++ b/libmemcached/dump.c @@ -29,7 +29,7 @@ static memcached_return_t ascii_dump(memcached_st *ptr, memcached_dump_fn *callb send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "stats cachedump %u 0 0\r\n", x); - rc= memcached_do(instance, buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, true); unlikely (rc != MEMCACHED_SUCCESS) goto error; diff --git a/libmemcached/flush.c b/libmemcached/flush.c index cb044b0c..8e1361a8 100644 --- a/libmemcached/flush.c +++ b/libmemcached/flush.c @@ -43,7 +43,7 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "flush_all%s\r\n", no_reply ? " noreply" : ""); - rc= memcached_do(instance, buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, true); if (rc == MEMCACHED_SUCCESS && !no_reply) (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); @@ -83,7 +83,7 @@ static memcached_return_t memcached_flush_binary(memcached_st *ptr, } if (memcached_do(instance, request.bytes, - sizeof(request.bytes), 1) != MEMCACHED_SUCCESS) + sizeof(request.bytes), true) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; diff --git a/libmemcached/get.c b/libmemcached/get.c index 051197b1..990f9bbf 100644 --- a/libmemcached/get.c +++ b/libmemcached/get.c @@ -144,7 +144,7 @@ static memcached_return_t memcached_mget_by_key_real(memcached_st *ptr, size_t number_of_keys, bool mget_mode) { - unsigned int x; + uint32_t x; memcached_return_t rc= MEMCACHED_NOTFOUND; const char *get_command= "get "; uint8_t get_command_length= 4; @@ -409,7 +409,7 @@ static memcached_return_t simple_binary_mget(memcached_st *ptr, if ((memcached_io_write(instance, request.bytes, sizeof(request.bytes), false) == -1) || (memcached_io_write(instance, keys[x], - key_length[x], (char) flush) == -1)) + key_length[x], flush) == -1)) { memcached_server_response_reset(instance); rc= MEMCACHED_SOME_ERRORS; diff --git a/libmemcached/include.am b/libmemcached/include.am index 56818911..aa96d923 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -10,6 +10,7 @@ EXTRA_DIST+= \ noinst_HEADERS+= \ libmemcached/byteorder.h \ libmemcached/common.h \ + libmemcached/do.h \ libmemcached/internal.h \ libmemcached/io.h \ libmemcached/libmemcached_probes.h \ diff --git a/libmemcached/quit.c b/libmemcached/quit.c index c22635a8..ebeffa5c 100644 --- a/libmemcached/quit.c +++ b/libmemcached/quit.c @@ -24,11 +24,11 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) request.message.header.request.magic = PROTOCOL_BINARY_REQ; request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; - rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), 1); + rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), true); } else { - rc= memcached_do(ptr, "quit\r\n", 6, 1); + rc= memcached_do(ptr, "quit\r\n", sizeof("quit\r\n"), true); } WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED); diff --git a/libmemcached/stats.c b/libmemcached/stats.c index e38445ec..128a92f7 100644 --- a/libmemcached/stats.c +++ b/libmemcached/stats.c @@ -250,7 +250,7 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, request.message.header.request.bodylen= htonl((uint32_t) len); if ((memcached_do(instance, request.bytes, - sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) || + sizeof(request.bytes), false) != MEMCACHED_SUCCESS) || (memcached_io_write(instance, args, len, true) == -1)) { memcached_io_reset(instance); @@ -260,7 +260,7 @@ static memcached_return_t binary_stats_fetch(memcached_stat_st *memc_stat, else { if (memcached_do(instance, request.bytes, - sizeof(request.bytes), 1) != MEMCACHED_SUCCESS) + sizeof(request.bytes), true) != MEMCACHED_SUCCESS) { memcached_io_reset(instance); return MEMCACHED_WRITE_FAILURE; @@ -314,7 +314,7 @@ static memcached_return_t ascii_stats_fetch(memcached_stat_st *memc_stat, if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; - rc= memcached_do(instance, buffer, send_length, 1); + rc= memcached_do(instance, buffer, send_length, true); if (rc != MEMCACHED_SUCCESS) goto error; diff --git a/libmemcached/storage.c b/libmemcached/storage.c index 6b4eb623..7a96b778 100644 --- a/libmemcached/storage.c +++ b/libmemcached/storage.c @@ -65,7 +65,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, uint64_t cas, memcached_storage_action_t verb) { - char to_write; + bool to_write; size_t write_length; memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -149,7 +149,7 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, } /* Send command header */ - rc= memcached_do(instance, buffer, write_length, 0); + rc= memcached_do(instance, buffer, write_length, false); if (rc != MEMCACHED_SUCCESS) goto error; @@ -162,11 +162,11 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, if (ptr->flags.buffer_requests && verb == SET_OP) { - to_write= 0; + to_write= false; } else { - to_write= 1; + to_write= true; } if (memcached_io_write(instance, "\r\n", 2, to_write) == -1) @@ -176,9 +176,9 @@ static inline memcached_return_t memcached_send(memcached_st *ptr, } if (ptr->flags.no_reply) - return (to_write == 0) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; + return (to_write == false) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; - if (to_write == 0) + if (to_write == false) return MEMCACHED_BUFFERED; rc= memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL); @@ -441,7 +441,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, uint64_t cas, memcached_storage_action_t verb) { - uint8_t flush; + bool flush; protocol_binary_request_set request= {.bytes= {0}}; size_t send_length= sizeof(request.bytes); uint32_t server_key= memcached_generate_hash(ptr, master_key, @@ -471,9 +471,9 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, if (cas) request.message.header.request.cas= htonll(cas); - flush= (uint8_t) ((server->root->flags.buffer_requests && verb == SET_OP) ? 0 : 1); + flush= (bool) ((server->root->flags.buffer_requests && verb == SET_OP) ? 0 : 1); - if (server->root->flags.use_udp && !flush) + if (server->root->flags.use_udp && ! flush) { size_t cmd_size= send_length + key_length + value_length; @@ -488,9 +488,9 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, } /* write the header */ - if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) || + if ((memcached_do(server, (const char*)request.bytes, send_length, false) != MEMCACHED_SUCCESS) || (memcached_io_write(server, key, key_length, false) == -1) || - (memcached_io_write(server, value, value_length, (char) flush) == -1)) + (memcached_io_write(server, value, value_length, flush) == -1)) { memcached_io_reset(server); return MEMCACHED_WRITE_FAILURE; @@ -511,9 +511,9 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, instance= memcached_server_instance_fetch(ptr, server_key); if ((memcached_do(instance, (const char*)request.bytes, - send_length, 0) != MEMCACHED_SUCCESS) || + send_length, false) != MEMCACHED_SUCCESS) || (memcached_io_write(instance, key, key_length, false) == -1) || - (memcached_io_write(instance, value, value_length, (char) flush) == -1)) + (memcached_io_write(instance, value, value_length, flush) == -1)) { memcached_io_reset(instance); } @@ -524,7 +524,7 @@ static memcached_return_t memcached_send_binary(memcached_st *ptr, } } - if (flush == 0) + if (flush == false) { return MEMCACHED_BUFFERED; } diff --git a/libmemcached/verbosity.c b/libmemcached/verbosity.c index 7c7b7ae1..e9fa3ef4 100644 --- a/libmemcached/verbosity.c +++ b/libmemcached/verbosity.c @@ -19,7 +19,7 @@ memcached_return_t memcached_verbosity(memcached_st *ptr, uint32_t verbosity) memcached_server_instance_st *instance= memcached_server_instance_fetch(ptr, x); - rrc= memcached_do(instance, buffer, send_length, 1); + rrc= memcached_do(instance, buffer, send_length, true); if (rrc != MEMCACHED_SUCCESS) { rc= MEMCACHED_SOME_ERRORS; diff --git a/libmemcached/version.c b/libmemcached/version.c index d854efdc..e3541d06 100644 --- a/libmemcached/version.c +++ b/libmemcached/version.c @@ -21,7 +21,6 @@ memcached_return_t memcached_version(memcached_st *ptr) static inline memcached_return_t memcached_version_textual(memcached_st *ptr) { - unsigned int x; size_t send_length; memcached_return_t rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; @@ -31,13 +30,13 @@ static inline memcached_return_t memcached_version_textual(memcached_st *ptr) send_length= strlen(command); rc= MEMCACHED_SUCCESS; - for (x= 0; x < memcached_server_count(ptr); x++) + for (uint32_t x= 0; x < memcached_server_count(ptr); x++) { memcached_return_t rrc; memcached_server_instance_st *instance= memcached_server_instance_fetch(ptr, x); - rrc= memcached_do(instance, command, send_length, 1); + rrc= memcached_do(instance, command, send_length, true); if (rrc != MEMCACHED_SUCCESS) { rc= MEMCACHED_SOME_ERRORS; @@ -84,7 +83,7 @@ static inline memcached_return_t memcached_version_binary(memcached_st *ptr) memcached_server_instance_st *instance= memcached_server_instance_fetch(ptr, x); - rrc= memcached_do(instance, request.bytes, sizeof(request.bytes), 1); + rrc= memcached_do(instance, request.bytes, sizeof(request.bytes), true); if (rrc != MEMCACHED_SUCCESS) { memcached_io_reset(instance);