From 51b7ba7ebf97f73f4669dcbca5dfa845fa812ed3 Mon Sep 17 00:00:00 2001 From: bspark Date: Sat, 23 Nov 2019 01:41:10 +0900 Subject: [PATCH] remove unnecessary whitespaces --- JSON_handler.cpp | 18 +++++++------- JSON_handler.h | 10 ++++---- client.cpp | 20 ++++++++-------- config_types.cpp | 8 +++---- config_types.h | 4 ++-- file_io.cpp | 44 +++++++++++++++++----------------- file_io.h | 2 +- item.cpp | 10 ++++---- item.h | 4 ++-- obj_gen.cpp | 34 +++++++++++++-------------- obj_gen.h | 10 ++++---- protocol.cpp | 56 ++++++++++++++++++++++---------------------- protocol.h | 8 +++---- shard_connection.cpp | 2 +- 14 files changed, 115 insertions(+), 115 deletions(-) diff --git a/JSON_handler.cpp b/JSON_handler.cpp index 95e1e595..c2b9943a 100644 --- a/JSON_handler.cpp +++ b/JSON_handler.cpp @@ -34,12 +34,12 @@ json_handler::json_handler(const char * jsonfilename) : m_json_file(NULL) m_json_file = fopen(jsonfilename, "w"); if (!m_json_file) { perror(jsonfilename); - } + } // opening the JSON fprintf(stderr, "Json file %s created...\n", jsonfilename); - fprintf(m_json_file,"{"); + fprintf(m_json_file,"{"); m_nest_closer_types.push_back(NESTED_GENERAL); - beutify(); + beutify(); } /** @@ -57,7 +57,7 @@ json_handler::~json_handler() } } -/** +/** * Write singel object named objectname to the JSON with values stated in ... * based on the format defined * basically uses fprintf with the same parameters. @@ -73,7 +73,7 @@ void json_handler::write_obj(const char * objectname, const char * format, ...) fprintf(m_json_file, ","); } -/** +/** * Starts a nesting with a title as defined in objectname * in case objectname == NULL it will not add the title and just start nesting * The type defines the kind of charecters that will be used @@ -90,9 +90,9 @@ void json_handler::open_nesting(const char * objectname,eJSON_NESTED_TYPE type / beutify(false); } -/** +/** * Ends the nesting - * Closes the nesting based on the nesting list + * Closes the nesting based on the nesting list * Returns = the nested levels left after the closing */ int json_handler::close_nesting() @@ -115,7 +115,7 @@ int json_handler::close_nesting() return m_nest_closer_types.size(); } -/** +/** * Add tabls and new line (if only_tabs==true will only add tabs) */ void json_handler::beutify(bool only_tabs) @@ -129,5 +129,5 @@ void json_handler::beutify(bool only_tabs) { fprintf(m_json_file, "\t"); } - + } diff --git a/JSON_handler.h b/JSON_handler.h index c5b5ef96..88733158 100644 --- a/JSON_handler.h +++ b/JSON_handler.h @@ -30,24 +30,24 @@ typedef enum{ NESTED_ARRAY // [] }eJSON_NESTED_TYPE; -/** represents an JSON handler, At this phase, only writes to JSON. */ +/** represents an JSON handler, At this phase, only writes to JSON. */ class json_handler { protected: - FILE * m_json_file; + FILE * m_json_file; // This list is used later for closing the nesting std::list m_nest_closer_types; void beutify(bool only_tabs = false); public: json_handler(const char * jsonfilename); ~json_handler(); - + // Write a single object to JSON void write_obj(const char * objectname, const char * format, ...); - // Starts nesting, the type is used for deciding which charecter to be used for opening and closing + // Starts nesting, the type is used for deciding which charecter to be used for opening and closing // the nesting ('{}','[]') void open_nesting(const char * objectname,eJSON_NESTED_TYPE type = NESTED_GENERAL); - + // returns the nested level left after closing int close_nesting(); }; diff --git a/client.cpp b/client.cpp index 114b35d3..f5833796 100755 --- a/client.cpp +++ b/client.cpp @@ -125,7 +125,7 @@ client::client(struct event_base *event_base, benchmark_config *config, if (!setup_client(config, protocol, obj_gen)) { return; } - + benchmark_debug_log("new client %p successfully set up.\n", this); m_initialized = true; } @@ -203,7 +203,7 @@ bool client::finished(void) return true; if (m_config->test_time > 0 && m_stats.get_duration() >= m_config->test_time) return true; - return false; + return false; } void client::set_start_time() { @@ -333,7 +333,7 @@ void client::create_request(struct timeval timestamp, unsigned int conn_id) assert(key != NULL); assert(keylen > 0); - + m_keylist->add_key(key, keylen); } @@ -353,14 +353,14 @@ void client::create_request(struct timeval timestamp, unsigned int conn_id) } else { // overlap counters m_get_ratio_count = m_set_ratio_count = 0; - } + } } int client::prepare(void) { if (MAIN_CONNECTION == NULL) return -1; - + int ret = this->connect(); if (ret < 0) { benchmark_error_log("prepare: failed to connect, test aborted.\n"); @@ -522,7 +522,7 @@ bool verify_client::finished(void) /////////////////////////////////////////////////////////////////////////// -client_group::client_group(benchmark_config* config, abstract_protocol *protocol, object_generator* obj_gen) : +client_group::client_group(benchmark_config* config, abstract_protocol *protocol, object_generator* obj_gen) : m_base(NULL), m_config(config), m_protocol(protocol), m_obj_gen(obj_gen) { m_base = event_base_new(); @@ -561,7 +561,7 @@ int client_group::create_clients(int num) delete c; return i; } - + m_clients.push_back(c); } @@ -625,14 +625,14 @@ unsigned long int client_group::get_duration_usec(void) float factor = ((float)(thread_counter - 1) / thread_counter); duration = factor * duration + (float)(*i)->get_stats()->get_duration_usec() / thread_counter ; } - + return duration; } void client_group::merge_run_stats(run_stats* target) { assert(target != NULL); - unsigned int iteration_counter = 1; + unsigned int iteration_counter = 1; for (std::vector::iterator i = m_clients.begin(); i != m_clients.end(); i++) { target->merge(*(*i)->get_stats(), iteration_counter++); } @@ -649,5 +649,5 @@ void client_group::write_client_stats(const char *prefix) if (!(*i)->get_stats()->save_csv(filename, m_config)) { fprintf(stderr, "error: %s: failed to write client stats.\n", filename); } - } + } } diff --git a/config_types.cpp b/config_types.cpp index 1876f54a..41d45547 100644 --- a/config_types.cpp +++ b/config_types.cpp @@ -84,7 +84,7 @@ config_ratio::config_ratio(const char *ratio_str) : if (!q || *q != '\0') { a = b = 0; return; - } + } } config_weight_list::config_weight_list() : @@ -98,7 +98,7 @@ config_weight_list::config_weight_list(const config_weight_list& copy) : for (std::vector::const_iterator i = copy.item_list.begin(); i != copy.item_list.end(); i++) { const weight_item wi = *i; item_list.push_back(wi); - } + } next_size_iter = item_list.begin(); } @@ -111,7 +111,7 @@ config_weight_list& config_weight_list::operator=(const config_weight_list& rhs) for (std::vector::const_iterator i = rhs.item_list.begin(); i != rhs.item_list.end(); i++) { const weight_item wi = *i; item_list.push_back(wi); - } + } next_size_iter = item_list.begin(); return *this; } @@ -184,7 +184,7 @@ const char* config_weight_list::print(char *buf, int buf_len) *buf = '\0'; for (std::vector::iterator i = item_list.begin(); i != item_list.end(); i++) { - int n = snprintf(buf, buf_len, "%s%u:%u", + int n = snprintf(buf, buf_len, "%s%u:%u", i != item_list.begin() ? "," : "", i->size, i->weight); buf += n; buf_len -= n; diff --git a/config_types.h b/config_types.h index f46fb87d..58a24111 100644 --- a/config_types.h +++ b/config_types.h @@ -51,7 +51,7 @@ struct config_weight_list { unsigned int size; unsigned int weight; }; - + std::vector item_list; std::vector::iterator next_size_iter; unsigned int next_size_weight; @@ -60,7 +60,7 @@ struct config_weight_list { config_weight_list(const char* str); config_weight_list(const config_weight_list& copy); config_weight_list& operator=(const config_weight_list& rhs); - + bool is_defined(void); unsigned int largest(void); const char *print(char *buf, int buf_len); diff --git a/file_io.cpp b/file_io.cpp index 8bdca3e7..4990fb47 100644 --- a/file_io.cpp +++ b/file_io.cpp @@ -31,7 +31,7 @@ * \param filename name of file to open. */ file_reader::file_reader(const char *filename) : - m_filename(filename), m_file(NULL), + m_filename(filename), m_file(NULL), m_line(2) { } @@ -55,7 +55,7 @@ file_reader::file_reader(const file_reader& from) : * this method reads the file header and verifies that it is valid. * \return true for success, false for error. */ - + bool file_reader::open_file(void) { char header_line[80]; @@ -65,7 +65,7 @@ bool file_reader::open_file(void) if (m_file != NULL) fclose(m_file); - + m_file = fopen(m_filename, "r"); if (!m_file) { perror(m_filename); @@ -102,7 +102,7 @@ bool file_reader::open_file(void) * \param actual_len pointer to unsigned int in which the actual string length read is returned * \return pointer to allocated buffer, or NULL on error. */ - + char* file_reader::read_string(unsigned int len, unsigned int alloc_len, unsigned int* actual_len) @@ -112,7 +112,7 @@ char* file_reader::read_string(unsigned int len, bool skip_quote = false; bool first_byte = true; bool dequote = false; - + d = dest_str = (char *) malloc(alloc_len); while (len > 0) { int c = fgetc(m_file); @@ -124,7 +124,7 @@ char* file_reader::read_string(unsigned int len, continue; } } - + // did we hit the eof? if (c == EOF) { fprintf(stderr, "%s:%d: premature end of file.\n", m_filename, m_line); @@ -135,7 +135,7 @@ char* file_reader::read_string(unsigned int len, if (skip_quote && c != '"') { break; } - + if (c == '"') { if (skip_quote) { skip_quote = false; @@ -156,7 +156,7 @@ char* file_reader::read_string(unsigned int len, fseek(m_file, -1, SEEK_CUR); break; } - + // copy *d = (char) c; d++; @@ -177,14 +177,14 @@ char* file_reader::read_string(unsigned int len, m_filename, m_line); } } - + int c = fgetc(m_file); if (c != '"') { fprintf(stderr, "%s:%d: warning: missing '\"' at end of column (got '%c').\n", m_filename, m_line, c); } } - + if (actual_len != NULL) *actual_len = (d - dest_str); @@ -202,7 +202,7 @@ bool file_reader::is_eof(void) /** \brief read the next memcache_item object from the opened file. * \return pointer to heap-allocated object, or NULL if error/no more items in file. */ - + memcache_item* file_reader::read_item(void) { // parse next line @@ -228,7 +228,7 @@ memcache_item* file_reader::read_item(void) if (is_eof()) return NULL; - + fprintf(stderr, "%s:%u: error parsing item values.\n", m_filename, m_line); return NULL; @@ -242,17 +242,17 @@ memcache_item* file_reader::read_item(void) m_filename, m_line, key_actlen, s_nkey); } key[s_nkey] = '\0'; - + // read data int c = fgetc(m_file); if (c != ',') { - fprintf(stderr, "%s:%u: error parsing csv file, got '%c' instead of delmiter.\n", + fprintf(stderr, "%s:%u: error parsing csv file, got '%c' instead of delmiter.\n", m_filename, m_line, c); free(key); return NULL; } fgetc(m_file); - + unsigned int data_actlen = 0; char *data = read_string(s_nbytes - 2, s_nbytes, &data_actlen); if (data_actlen != s_nbytes - 2) { @@ -278,11 +278,11 @@ memcache_item* file_reader::read_item(void) m_line++; // return item - memcache_item *item = new memcache_item(s_dumpflags, + memcache_item *item = new memcache_item(s_dumpflags, s_time, s_exptime, s_flags, s_nsuffix, s_clsid); item->set_key(key, s_nkey); item->set_data(data, s_nbytes); - + return item; } @@ -323,7 +323,7 @@ bool file_writer::open_file(void) return false; } - fprintf(m_file, + fprintf(m_file, "dumpflags, time, exptime, nbytes, nsuffix, it_flags, clsid, nkey, key, data\n"); return true; } @@ -339,7 +339,7 @@ bool file_writer::open_file(void) * \param new_str_len pointer to int which will be set with the new, quoted string length. * \return pointer to quoted string, or to the same string if quoting is not needed. */ - + char* file_writer::get_quoted_str(char* str, int str_len, int* new_str_len) { char *new_str; @@ -347,7 +347,7 @@ char* file_writer::get_quoted_str(char* str, int str_len, int* new_str_len) char *s; *new_str_len = str_len; - + // is it necessary? if (memchr(str, '"', str_len) == NULL) { return str; @@ -384,7 +384,7 @@ bool file_writer::write_item(memcache_item *item) char *quoted_data; int quoted_data_len; - quoted_key = get_quoted_str(item->get_key(), + quoted_key = get_quoted_str(item->get_key(), item->get_nkey(), "ed_key_len); quoted_data = get_quoted_str(item->get_data(), item->get_nbytes() - 2, "ed_data_len); @@ -413,5 +413,5 @@ bool file_writer::write_item(memcache_item *item) if (quoted_data != item->get_data()) free(quoted_data); - return true; + return true; } diff --git a/file_io.h b/file_io.h index bd9d8315..3c4cbd98 100644 --- a/file_io.h +++ b/file_io.h @@ -52,7 +52,7 @@ class file_writer { FILE *m_file; /** handle of open file */ char* get_quoted_str(char* str, int str_len, int* new_str_len); - + public: file_writer(const char *filename); ~file_writer(); diff --git a/item.cpp b/item.cpp index f3d1b3f9..67c97719 100644 --- a/item.cpp +++ b/item.cpp @@ -27,10 +27,10 @@ memcache_item::memcache_item(unsigned int dumpflags, time_t time, time_t exptime, - unsigned short flags, + unsigned short flags, unsigned int nsuffix, - unsigned int clsid) : - m_dumpflags(dumpflags), m_time(time), m_exptime(exptime), + unsigned int clsid) : + m_dumpflags(dumpflags), m_time(time), m_exptime(exptime), m_flags(flags), m_nsuffix(nsuffix), m_clsid(clsid), m_version(0) { @@ -50,7 +50,7 @@ memcache_item::~memcache_item() * \param key pointer to malloc() allocated key data. * \param nkey length of key. */ - + void memcache_item::set_key(char *key, unsigned int nkey) { if (m_key != NULL) @@ -63,7 +63,7 @@ void memcache_item::set_key(char *key, unsigned int nkey) * \param data pointer to malloc() allocated data. * \param nbytes length of data. */ - + void memcache_item::set_data(char *data, unsigned int nbytes) { if (m_data != NULL) diff --git a/item.h b/item.h index d4a0c59a..4e932296 100644 --- a/item.h +++ b/item.h @@ -26,12 +26,12 @@ /** \name values of the bitwise dump flag */ #define ITEM_DUMPFLAGS_EXPIRED 0x0001 /** item's expiration time has passed when dump conducted */ -/** represents a memcache item while it's being processed by the tool. */ +/** represents a memcache item while it's being processed by the tool. */ class memcache_item { protected: unsigned int m_dumpflags; /** from file: dump flags (added by memcache_dump) */ time_t m_time; /** from file: time (last modified time) */ - time_t m_exptime; /** from file: exptime (expiration time) */ + time_t m_exptime; /** from file: exptime (expiration time) */ unsigned int m_nbytes; /** from file: nbytes (size of data, including trailing CRLF) */ unsigned int m_nkey; /** from file: nkey (size of key) */ unsigned short m_flags; /** from file: flags (internal memcached) */ diff --git a/obj_gen.cpp b/obj_gen.cpp index def166a4..c60ceab1 100644 --- a/obj_gen.cpp +++ b/obj_gen.cpp @@ -45,7 +45,7 @@ void random_generator::set_seed(int seed) #ifdef HAVE_RANDOM_R memset(&m_data_blob, 0, sizeof(m_data_blob)); memset(m_state_array, 0, sizeof(m_state_array)); - + int ret = initstate_r(seed, m_state_array, sizeof(m_state_array), &m_data_blob); assert(ret == 0); #elif (defined HAVE_DRAND48) @@ -106,7 +106,7 @@ double gaussian_noise::gaussian_distribution(const double &stddev) m_hasSpare = false; return stddev * m_spare; } - + m_hasSpare = true; double u, v, s; do { @@ -114,7 +114,7 @@ double gaussian_noise::gaussian_distribution(const double &stddev) v = (get_random() / ((double) get_random_max())) * 2 - 1; s = u * u + v * v; } while(s >= 1 || s == 0); - + s = sqrt(-2.0 * log(s) / s); m_spare = v * s; return stddev * u * s; @@ -160,7 +160,7 @@ object_generator::object_generator(size_t n_key_iterators/*= OBJECT_GENERATOR_KE m_data_size.size_list = NULL; } -object_generator::object_generator(const object_generator& copy) : +object_generator::object_generator(const object_generator& copy) : m_data_size_type(copy.m_data_size_type), m_data_size(copy.m_data_size), m_data_size_pattern(copy.m_data_size_pattern), @@ -213,11 +213,11 @@ void object_generator::set_random_seed(int seed) void object_generator::alloc_value_buffer(void) { unsigned int size = 0; - + if (m_value_buffer != NULL) free(m_value_buffer), m_value_buffer = NULL; - if (m_data_size_type == data_size_fixed) + if (m_data_size_type == data_size_fixed) size = m_data_size.size_fixed; else if (m_data_size_type == data_size_range) size = m_data_size.size_range.size_max; @@ -244,14 +244,14 @@ void object_generator::alloc_value_buffer(void) char *d = m_value_buffer; int ret; int iter = 0; - + while (d - m_value_buffer < size) { if (buf1_idx == sizeof(buf1)) { buf1_idx = 0; - buf2_idx++; + buf2_idx++; if (buf2_idx == sizeof(buf2)) { iter++; - if (iter == 20) { + if (iter == 20) { ret = read(m_random_fd, buf1, sizeof(buf1)); assert(ret > -1); ret = read(m_random_fd, buf2, sizeof(buf2)); @@ -410,8 +410,8 @@ data_object* object_generator::get_object(int iter) // set object m_object.set_key(m_key_buffer, strlen(m_key_buffer)); m_object.set_value(m_value_buffer, new_size); - m_object.set_expiry(expiry); - + m_object.set_expiry(expiry); + return &m_object; } @@ -473,7 +473,7 @@ data_object::~data_object() clear(); } -void data_object::clear(void) +void data_object::clear(void) { m_key = NULL; m_key_len = 0; @@ -492,7 +492,7 @@ const char* data_object::get_key(unsigned int* key_len) { assert(key_len != NULL); *key_len = m_key_len; - + return m_key; } @@ -523,7 +523,7 @@ unsigned int data_object::get_expiry(void) /////////////////////////////////////////////////////////////////////////// imported_keylist::imported_keylist(const char *filename) - : m_filename(filename) + : m_filename(filename) { } @@ -634,7 +634,7 @@ const char* import_object_generator::get_key(int iter, unsigned int *len) } data_object* import_object_generator::get_object(int iter) -{ +{ memcache_item *i = m_reader.read_item(); if (i == NULL && m_reader.is_eof()) { @@ -647,7 +647,7 @@ data_object* import_object_generator::get_object(int iter) delete m_cur_item; } m_cur_item = i; - + m_object.set_value(m_cur_item->get_data(), m_cur_item->get_nbytes() - 2); if (m_keys != NULL) { m_object.set_key(m_cur_item->get_key(), m_cur_item->get_nkey()); @@ -656,7 +656,7 @@ data_object* import_object_generator::get_object(int iter) const char *tmpkey = object_generator::get_key(iter, &tmplen); m_object.set_key(tmpkey, tmplen); } - + // compute expiry int expiry = 0; if (!m_no_expiry) { diff --git a/obj_gen.h b/obj_gen.h index 5a0f8f71..e1c1cc0b 100644 --- a/obj_gen.h +++ b/obj_gen.h @@ -51,7 +51,7 @@ class gaussian_noise: public random_generator { }; class data_object { -protected: +protected: const char *m_key; unsigned int m_key_len; const char *m_value; @@ -67,7 +67,7 @@ class data_object { void set_value(const char* value, unsigned int value_len); const char* get_value(unsigned int* value_len); void set_expiry(unsigned int expiry); - unsigned int get_expiry(void); + unsigned int get_expiry(void); }; #define OBJECT_GENERATOR_KEY_ITERATORS 2 /* number of iterators */ @@ -109,11 +109,11 @@ class object_generator { gaussian_noise m_random; unsigned int m_value_buffer_size; unsigned int m_value_buffer_mutation_pos; - + void alloc_value_buffer(void); void alloc_value_buffer(const char* copy_from); void random_init(void); -public: +public: object_generator(size_t n_key_iterators = OBJECT_GENERATOR_KEY_ITERATORS); object_generator(const object_generator& copy); virtual ~object_generator(); @@ -128,7 +128,7 @@ class object_generator { void set_data_size_list(config_weight_list* data_size_list); void set_data_size_pattern(const char* pattern); void set_expiry_range(unsigned int expiry_min, unsigned int expiry_max); - void set_key_prefix(const char *key_prefix); + void set_key_prefix(const char *key_prefix); void set_key_range(unsigned long long key_min, unsigned long long key_max); void set_key_distribution(double key_stddev, double key_median); void set_random_seed(int seed); diff --git a/protocol.cpp b/protocol.cpp index ca3c04b9..ab9e4b5f 100644 --- a/protocol.cpp +++ b/protocol.cpp @@ -35,7 +35,7 @@ abstract_protocol::abstract_protocol() : m_read_buf(NULL), m_write_buf(NULL), m_keep_value(false) -{ +{ } abstract_protocol::~abstract_protocol() @@ -109,7 +109,7 @@ void protocol_response::set_total_len(unsigned int total_len) } unsigned int protocol_response::get_total_len(void) -{ +{ return m_total_len; } @@ -266,7 +266,7 @@ int redis_protocol::write_command_set(const char *key, int key_len, const char * } else { char expiry_str[30]; snprintf(expiry_str, sizeof(expiry_str)-1, "%u", expiry); - + size = evbuffer_add_printf(m_write_buf, "*4\r\n" "$5\r\n" @@ -298,7 +298,7 @@ int redis_protocol::write_command_get(const char *key, int key_len, unsigned int assert(key != NULL); assert(key_len > 0); int size = 0; - + if (!offset) { size = evbuffer_add_printf(m_write_buf, "*2\r\n" @@ -306,7 +306,7 @@ int redis_protocol::write_command_get(const char *key, int key_len, unsigned int "GET\r\n" "$%u\r\n", key_len); evbuffer_add(m_write_buf, key, key_len); - evbuffer_add(m_write_buf, "\r\n", 2); + evbuffer_add(m_write_buf, "\r\n", 2); size += key_len + 2; } else { char offset_str[30]; @@ -324,7 +324,7 @@ int redis_protocol::write_command_get(const char *key, int key_len, unsigned int "$%u\r\n" "%s\r\n" "$2\r\n" - "-1\r\n", (unsigned int) strlen(offset_str), offset_str); + "-1\r\n", (unsigned int) strlen(offset_str), offset_str); } return size; @@ -659,7 +659,7 @@ int memcache_text_protocol::write_command_set(const char *key, int key_len, cons assert(value != NULL); assert(value_len > 0); int size = 0; - + size = evbuffer_add_printf(m_write_buf, "set %.*s 0 %u %u\r\n", key_len, key, expiry, value_len); evbuffer_add(m_write_buf, value, value_len); @@ -691,18 +691,18 @@ int memcache_text_protocol::write_command_multi_get(const keylist *keylist) n = evbuffer_add(m_write_buf, "get", 3); assert(n != -1); size = 3; - + for (unsigned int i = 0; i < keylist->get_keys_count(); i++) { const char *key; unsigned int key_len; - + n = evbuffer_add(m_write_buf, " ", 1); assert(n != -1); size++; key = keylist->get_key(i, &key_len); assert(key != NULL); - + n = evbuffer_add(m_write_buf, key, key_len); assert(n != -1); size += key_len; @@ -725,15 +725,15 @@ int memcache_text_protocol::parse_response(void) { char *line; size_t tmplen; - + while (true) { switch (m_response_state) { case rs_initial: m_last_response.clear(); m_response_state = rs_read_section; m_response_len = 0; - break; - + break; + case rs_read_section: line = evbuffer_readln(m_read_buf, &tmplen, EVBUFFER_EOL_CRLF_STRICT); if (!line) @@ -743,8 +743,8 @@ int memcache_text_protocol::parse_response(void) if (m_last_response.get_status() == NULL) { m_last_response.set_status(line); } - m_last_response.set_total_len((unsigned int) m_response_len); // for now... - + m_last_response.set_total_len((unsigned int) m_response_len); // for now... + if (memcmp(line, "VALUE", 5) == 0) { char prefix[50]; char key[256]; @@ -773,13 +773,13 @@ int memcache_text_protocol::parse_response(void) return -1; } break; - - case rs_read_value: + + case rs_read_value: if (evbuffer_get_length(m_read_buf) >= m_value_len + 2) { if (m_keep_value) { char *value = (char *) malloc(m_value_len); assert(value != NULL); - + int ret = evbuffer_remove(m_read_buf, value, m_value_len); assert((unsigned int) ret == 0); @@ -802,7 +802,7 @@ int memcache_text_protocol::parse_response(void) case rs_read_end: m_response_state = rs_initial; return 1; - + default: benchmark_debug_log("unknown response state %d.\n", m_response_state); return -1; @@ -877,7 +877,7 @@ int memcache_binary_protocol::authenticate(const char *credentials) user_len = colon - user; passwd = colon + 1; passwd_len = strlen(passwd); - + memset(&req, 0, sizeof(req)); req.message.header.request.magic = PROTOCOL_BINARY_REQ; req.message.header.request.opcode = PROTOCOL_BINARY_CMD_SASL_AUTH; @@ -1001,7 +1001,7 @@ int memcache_binary_protocol::parse_response(void) while (true) { int ret; int status; - + switch (m_response_state) { case rs_initial: if (evbuffer_get_length(m_read_buf) < sizeof(m_response_hdr)) @@ -1030,21 +1030,21 @@ int memcache_binary_protocol::parse_response(void) status == PROTOCOL_BINARY_RESPONSE_EBUSY) { m_last_response.set_error(true); } - + if (ntohl(m_response_hdr.message.header.response.bodylen) > 0) { m_response_hdr.message.header.response.bodylen = ntohl(m_response_hdr.message.header.response.bodylen); m_response_hdr.message.header.response.keylen = ntohs(m_response_hdr.message.header.response.keylen); - + m_response_state = rs_read_body; continue; } - return 1; + return 1; break; case rs_read_body: if (evbuffer_get_length(m_read_buf) >= m_response_hdr.message.header.response.bodylen) { // get rid of extras and key, we don't care about them - ret = evbuffer_drain(m_read_buf, + ret = evbuffer_drain(m_read_buf, m_response_hdr.message.header.response.extlen + m_response_hdr.message.header.response.keylen); assert((unsigned int) ret == 0); @@ -1064,7 +1064,7 @@ int memcache_binary_protocol::parse_response(void) if (m_response_hdr.message.header.response.status == PROTOCOL_BINARY_RESPONSE_SUCCESS) m_last_response.incr_hits(); - + m_response_len += m_response_hdr.message.header.response.bodylen; m_response_state = rs_initial; @@ -1129,8 +1129,8 @@ keylist::keylist(unsigned int max_keys) : assert(m_buffer != NULL); memset(m_buffer, 0, m_buffer_size); - m_buffer_ptr = m_buffer; -} + m_buffer_ptr = m_buffer; +} keylist::~keylist() { diff --git a/protocol.h b/protocol.h index c7fb19ae..b4855516 100644 --- a/protocol.h +++ b/protocol.h @@ -148,15 +148,15 @@ class keylist { char *key_ptr; unsigned int key_len; }; - + char *m_buffer; char *m_buffer_ptr; unsigned int m_buffer_size; - + key_entry *m_keys; unsigned int m_keys_size; unsigned int m_keys_count; - + public: keylist(unsigned int max_keys); ~keylist(); @@ -179,7 +179,7 @@ class abstract_protocol { abstract_protocol(); virtual ~abstract_protocol(); virtual abstract_protocol* clone(void) = 0; - void set_buffers(struct evbuffer* read_buf, struct evbuffer* write_buf); + void set_buffers(struct evbuffer* read_buf, struct evbuffer* write_buf); void set_keep_value(bool flag); virtual int select_db(int db) = 0; diff --git a/shard_connection.cpp b/shard_connection.cpp index 606384af..b9fe31c3 100644 --- a/shard_connection.cpp +++ b/shard_connection.cpp @@ -264,7 +264,7 @@ int shard_connection::connect(struct connect_info* addr) { // call connect m_connection_state = conn_in_progress; - if (bufferevent_socket_connect(m_bev, + if (bufferevent_socket_connect(m_bev, m_unix_sockaddr ? (struct sockaddr *) m_unix_sockaddr : addr->ci_addr, m_unix_sockaddr ? sizeof(struct sockaddr_un) : addr->ci_addrlen) == -1) { disconnect();