Fixed ILP32 issues
authorTrond Norbye <trond.norbye@sun.com>
Sun, 6 Dec 2009 09:02:23 +0000 (10:02 +0100)
committerTrond Norbye <trond.norbye@sun.com>
Sun, 6 Dec 2009 09:02:23 +0000 (10:02 +0100)
clients/memslap.c
clients/ms_conn.c
clients/ms_setting.c
clients/ms_thread.c
libmemcached/memcached_get.c

index 298453dda31727fafc7da54c87c7b41db47c615b..d08b4d9bd41404b6d41a166d57530fe750ad47ee 100644 (file)
 #define PROGRAM_DESCRIPTION \
                         "Generates workload against memcached servers."
 
+#ifdef __sun
+  /* For some odd reason the option struct on solaris defines the argument
+   * as char* and not const char*
+   */
+#define OPTIONSTRING char*
+#else
+#define OPTIONSTRING const char*
+#endif
+
 /* options */
 static struct option long_options[]=
 {
-  { "servers",        required_argument,            NULL,
+  { (OPTIONSTRING)"servers",        required_argument,            NULL,
     OPT_SERVERS            },
-  { "threads",        required_argument,            NULL,
+  { (OPTIONSTRING)"threads",        required_argument,            NULL,
     OPT_THREAD_NUMBER      },
-  { "concurrency",    required_argument,            NULL,
+  { (OPTIONSTRING)"concurrency",    required_argument,            NULL,
     OPT_CONCURRENCY        },
-  { "conn_sock",      required_argument,            NULL,
+  { (OPTIONSTRING)"conn_sock",      required_argument,            NULL,
     OPT_SOCK_PER_CONN      },
-  { "execute_number", required_argument,            NULL,
+  { (OPTIONSTRING)"execute_number", required_argument,            NULL,
     OPT_EXECUTE_NUMBER     },
-  { "time",           required_argument,            NULL,
+  { (OPTIONSTRING)"time",           required_argument,            NULL,
     OPT_TIME               },
-  { "cfg_cmd",        required_argument,            NULL,
+  { (OPTIONSTRING)"cfg_cmd",        required_argument,            NULL,
     OPT_CONFIG_CMD         },
-  { "win_size",       required_argument,            NULL,
+  { (OPTIONSTRING)"win_size",       required_argument,            NULL,
     OPT_WINDOW_SIZE        },
-  { "fixed_size",     required_argument,            NULL,
+  { (OPTIONSTRING)"fixed_size",     required_argument,            NULL,
     OPT_FIXED_LTH          },
-  { "verify",         required_argument,            NULL,
+  { (OPTIONSTRING)"verify",         required_argument,            NULL,
     OPT_VERIFY             },
-  { "division",       required_argument,            NULL,
+  { (OPTIONSTRING)"division",       required_argument,            NULL,
     OPT_GETS_DIVISION      },
-  { "stat_freq",      required_argument,            NULL,
+  { (OPTIONSTRING)"stat_freq",      required_argument,            NULL,
     OPT_STAT_FREQ          },
-  { "exp_verify",     required_argument,            NULL,
+  { (OPTIONSTRING)"exp_verify",     required_argument,            NULL,
     OPT_EXPIRE             },
-  { "overwrite",      required_argument,            NULL,
+  { (OPTIONSTRING)"overwrite",      required_argument,            NULL,
     OPT_OVERWRITE          },
-  { "reconnect",      no_argument,                  NULL,
+  { (OPTIONSTRING)"reconnect",      no_argument,                  NULL,
     OPT_RECONNECT          },
-  { "udp",            no_argument,                  NULL,
+  { (OPTIONSTRING)"udp",            no_argument,                  NULL,
     OPT_UDP                },
-  { "facebook",       no_argument,                  NULL,
+  { (OPTIONSTRING)"facebook",       no_argument,                  NULL,
     OPT_FACEBOOK_TEST      },
-  { "binary",         no_argument,                  NULL,
+  { (OPTIONSTRING)"binary",         no_argument,                  NULL,
     OPT_BINARY_PROTOCOL    },
-  { "tps",            required_argument,            NULL,
+  { (OPTIONSTRING)"tps",            required_argument,            NULL,
     OPT_TPS                },
-  { "rep_write",      required_argument,            NULL,
+  { (OPTIONSTRING)"rep_write",      required_argument,            NULL,
     OPT_REP_WRITE_SRV      },
-  { "verbose",        no_argument,                  NULL,
+  { (OPTIONSTRING)"verbose",        no_argument,                  NULL,
     OPT_VERBOSE            },
-  { "help",           no_argument,                  NULL,
+  { (OPTIONSTRING)"help",           no_argument,                  NULL,
     OPT_HELP               },
-  { "version",        no_argument,                  NULL,
+  { (OPTIONSTRING)"version",        no_argument,                  NULL,
     OPT_VERSION            },
-  { 0,                0,                            0,                 0                      },
+  { 0, 0, 0, 0 },
 };
 
 /* Prototypes */
index 59b0875d73db61a59d881626fdfc376740793c20..34707958aa0d21896c0fd6fe5b3e4f64187b857b 100644 (file)
 #include "ms_thread.h"
 #include "ms_atomic.h"
 
+#ifdef linux
+/* /usr/include/netinet/in.h defines macros from ntohs() to _bswap_nn to
+ * optimize the conversion functions, but the prototypes generate warnings
+ * from gcc. The conversion methods isn't the bottleneck for my app, so
+ * just remove the warnings by undef'ing the optimization ..
+ */
+#undef ntohs
+#undef ntohl
+#undef htons
+#undef htonl
+#endif
+
 /* for network write */
 #define TRANSMIT_COMPLETE      0
 #define TRANSMIT_INCOMPLETE    1
@@ -1272,7 +1284,7 @@ void ms_reset_conn(ms_conn_t *c, bool timeout)
   {
     if ((c->packets > 0) && (c->packets < MAX_UDP_PACKET))
     {
-      memset(c->udppkt, 0, sizeof(ms_udppkt_t) * (uint64_t)c->packets);
+      memset(c->udppkt, 0, sizeof(ms_udppkt_t) * (size_t)c->packets);
     }
 
     c->packets= 0;
@@ -1331,9 +1343,9 @@ static int ms_try_read_line(ms_conn_t *c)
 
       c->binary_header= *rsp;
       c->binary_header.response.extlen= rsp->response.extlen;
-      c->binary_header.response.keylen= ntohl(rsp->response.keylen);
+      c->binary_header.response.keylen= ntohs(rsp->response.keylen);
       c->binary_header.response.bodylen= ntohl(rsp->response.bodylen);
-      c->binary_header.response.status= ntohl(rsp->response.status);
+      c->binary_header.response.status= ntohs(rsp->response.status);
 
       if (c->binary_header.response.magic != PROTOCOL_BINARY_RES)
       {
@@ -2013,7 +2025,7 @@ static int ms_add_msghdr(ms_conn_t *c)
   if (c->msgsize == c->msgused)
   {
     msg=
-      realloc(c->msglist, (uint64_t)c->msgsize * 2 * sizeof(struct msghdr));
+      realloc(c->msglist, (size_t)c->msgsize * 2 * sizeof(struct msghdr));
     if (! msg)
       return -1;
 
@@ -2066,7 +2078,7 @@ static int ms_ensure_iov_space(ms_conn_t *c)
   {
     int i, iovnum;
     struct iovec *new_iov= (struct iovec *)realloc(c->iov,
-                                                   ((uint64_t)c->iovsize
+                                                   ((size_t)c->iovsize
                                                     * 2)
                                                    * sizeof(struct iovec));
     if (! new_iov)
@@ -2258,7 +2270,7 @@ static int ms_transmit(ms_conn_t *c)
       if (res > 0)
       {
         m->msg_iov->iov_base= (void *)((unsigned char *)m->msg_iov->iov_base + res);
-        m->msg_iov->iov_len-= (uint64_t)res;
+        m->msg_iov->iov_len-= (size_t)res;
       }
       return TRANSMIT_INCOMPLETE;
     }
@@ -3298,7 +3310,7 @@ static void ms_add_bin_header(ms_conn_t *c,
 
   header->request.magic= (uint8_t)PROTOCOL_BINARY_REQ;
   header->request.opcode= (uint8_t)opcode;
-  header->request.keylen= htonl(key_len);
+  header->request.keylen= htons(key_len);
 
   header->request.extlen= (uint8_t)hdr_len;
   header->request.datatype= (uint8_t)PROTOCOL_BINARY_RAW_BYTES;
index 52e4670fab0c8033e4d54d03911adceb75ae0eaf..2821ec524d2254bbb8713de66ef5e8f45d4d43b3 100644 (file)
@@ -89,9 +89,7 @@ static ssize_t getline (char **line, size_t *line_size, FILE *fp)
 
   for (;;)
   {
-    char i;
-
-    i = getc(fp);
+    int i= getc(fp);
     if (i == EOF)
     {
       result = -1;
@@ -126,7 +124,7 @@ static ssize_t getline (char **line, size_t *line_size, FILE *fp)
       *line_size= needed;
     }
 
-    (*line)[cur_len]= i;
+    (*line)[cur_len]= (char)i;
     cur_len++;
 
     if (i == delim)
@@ -200,7 +198,7 @@ static void ms_get_serverlist(char *str)
     {
       srvs= (ms_mcd_server_t *)realloc(
         ms_setting.servers,
-        (uint64_t)ms_setting.total_srv_cnt
+        (size_t)ms_setting.total_srv_cnt
         * sizeof(ms_mcd_server_t) * 2);
       if (srvs == NULL)
       {
@@ -400,7 +398,7 @@ static void ms_parse_cfg_file(char *cfg_file)
 
         if (nread != EOF)
         {
-          if (sscanf(line, "%lu %lu %lf ", &start_len,
+          if (sscanf(line, "%zu %zu %lf ", &start_len,
                      &end_len, &proportion) != 3)
           {
             conf_type= ms_get_conf_type(line);
@@ -415,7 +413,7 @@ static void ms_parse_cfg_file(char *cfg_file)
           {
             key_distr= (ms_key_distr_t *)realloc(
               ms_setting.key_distr,
-              (uint64_t)ms_setting.
+              (size_t)ms_setting.
                  total_key_rng_cnt * sizeof(ms_key_distr_t) * 2);
             if (key_distr == NULL)
             {
@@ -442,7 +440,7 @@ static void ms_parse_cfg_file(char *cfg_file)
 
         if (nread != EOF)
         {
-          if (sscanf(line, "%lu %lu %lf %lu", &start_len, &end_len,
+          if (sscanf(line, "%zu %zu %lf %zu", &start_len, &end_len,
                      &proportion, &frequence) != 3)
           {
             conf_type= ms_get_conf_type(line);
@@ -459,7 +457,7 @@ static void ms_parse_cfg_file(char *cfg_file)
           {
             val_distr= (ms_value_distr_t *)realloc(
               ms_setting.value_distr,
-              (uint64_t)ms_setting.
+              (size_t)ms_setting.
                  total_val_rng_cnt * sizeof(ms_value_distr_t) * 2);
             if (val_distr == NULL)
             {
@@ -911,7 +909,7 @@ void ms_setting_init_pre()
   ms_setting.run_time= DEFAULT_RUN_TIME;
   ms_setting.total_srv_cnt= MCD_SRVS_NUM_INIT;
   ms_setting.servers= (ms_mcd_server_t *)malloc(
-    (uint64_t)ms_setting.total_srv_cnt
+    (size_t)ms_setting.total_srv_cnt
     * sizeof(ms_mcd_server_t));
   if (ms_setting.servers == NULL)
   {
@@ -930,7 +928,7 @@ static void ms_setting_slapmode_init_post()
 {
   ms_setting.total_key_rng_cnt= KEY_RANGE_COUNT_INIT;
   ms_setting.key_distr= (ms_key_distr_t *)malloc(
-    (uint64_t)ms_setting.total_key_rng_cnt
+    (size_t)ms_setting.total_key_rng_cnt
     * sizeof(ms_key_distr_t));
   if (ms_setting.key_distr == NULL)
   {
@@ -940,7 +938,7 @@ static void ms_setting_slapmode_init_post()
 
   ms_setting.total_val_rng_cnt= VALUE_RANGE_COUNT_INIT;
   ms_setting.value_distr= (ms_value_distr_t *)malloc(
-    (uint64_t)ms_setting.total_val_rng_cnt
+    (size_t)ms_setting.total_val_rng_cnt
     * sizeof(
       ms_value_distr_t));
   if (ms_setting.value_distr == NULL)
index af856366c345ddea87ddbc9f2fd0a7693155d92c..5c387d0ee76303b0fa2dd289bcfd32a6d3f84e24 100644 (file)
@@ -61,7 +61,7 @@ static void ms_check_sock_timeout(void)
 
     if (c->udp)
     {
-      time_diff= (int)(ms_thread->curr_time - c->start_time.tv_sec);
+      time_diff= (int)(ms_thread->curr_time - (rel_time_t)c->start_time.tv_sec);
 
       /* wait time out */
       if (time_diff > SOCK_WAIT_TIMEOUT)
@@ -169,7 +169,7 @@ static int ms_set_thread_cpu_affinity(int cpu)
  */
 static int ms_setup_thread(ms_thread_ctx_t *thread_ctx)
 {
-  
+
   ms_thread_t *ms_thread= (ms_thread_t *)calloc(sizeof(*ms_thread), 1);
   pthread_setspecific(ms_thread_key, (void *)ms_thread);
 
index 0aa0f44c108d4e4ebe4dad8b1a5908201dc65427..9ba1388d4b5dbcb606497f022af44849d150dbc2 100644 (file)
@@ -1,32 +1,32 @@
 #include "common.h"
 #include "memcached_io.h"
 
-/* 
+/*
   What happens if no servers exist?
 */
-char *memcached_get(memcached_st *ptr, const char *key, 
-                    size_t key_length, 
-                    size_t *value_length, 
+char *memcached_get(memcached_st *ptr, const char *key,
+                    size_t key_length,
+                    size_t *value_length,
                     uint32_t *flags,
                     memcached_return *error)
 {
-  return memcached_get_by_key(ptr, NULL, 0, key, key_length, value_length, 
+  return memcached_get_by_key(ptr, NULL, 0, key, key_length, value_length,
                               flags, error);
 }
 
-static memcached_return memcached_mget_by_key_real(memcached_st *ptr, 
-                                                   const char *master_key, 
+static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
+                                                   const char *master_key,
                                                    size_t master_key_length,
-                                                   const char * const *keys, 
-                                                   const size_t *key_length, 
+                                                   const char * const *keys,
+                                                   const size_t *key_length,
                                                    size_t number_of_keys,
                                                    bool mget_mode);
 
-char *memcached_get_by_key(memcached_st *ptr, 
-                           const char *master_key, 
-                           size_t master_key_length, 
+char *memcached_get_by_key(memcached_st *ptr,
+                           const char *master_key,
+                           size_t master_key_length,
                            const char *key, size_t key_length,
-                           size_t *value_length, 
+                           size_t *value_length,
                            uint32_t *flags,
                            memcached_return *error)
 {
@@ -42,11 +42,11 @@ char *memcached_get_by_key(memcached_st *ptr,
   }
 
   /* Request the key */
-  *error= memcached_mget_by_key_real(ptr, master_key, master_key_length, 
-                                     (const char * const *)&key, 
+  *error= memcached_mget_by_key_real(ptr, master_key, master_key_length,
+                                     (const char * const *)&key,
                                      &key_length, 1, false);
 
-  value= memcached_fetch(ptr, NULL, NULL, 
+  value= memcached_fetch(ptr, NULL, NULL,
                          value_length, flags, error);
   /* This is for historical reasons */
   if (*error == MEMCACHED_END)
@@ -60,7 +60,7 @@ char *memcached_get_by_key(memcached_st *ptr,
 
       memcached_result_reset(&ptr->result);
       rc= ptr->get_key_failure(ptr, key, key_length, &ptr->result);
-      
+
       /* On all failure drop to returning NULL */
       if (rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED)
       {
@@ -71,7 +71,7 @@ char *memcached_get_by_key(memcached_st *ptr,
           if (latch == 0)
             memcached_behavior_set(ptr, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
 
-          rc= memcached_set(ptr, key, key_length, 
+          rc= memcached_set(ptr, key, key_length,
                             memcached_result_value(&ptr->result),
                             memcached_result_length(&ptr->result),
                             0, memcached_result_flags(&ptr->result));
@@ -81,7 +81,7 @@ char *memcached_get_by_key(memcached_st *ptr,
         }
         else
         {
-          rc= memcached_set(ptr, key, key_length, 
+          rc= memcached_set(ptr, key, key_length,
                             memcached_result_value(&ptr->result),
                             memcached_result_length(&ptr->result),
                             0, memcached_result_flags(&ptr->result));
@@ -100,17 +100,17 @@ char *memcached_get_by_key(memcached_st *ptr,
     return NULL;
   }
 
-  (void)memcached_fetch(ptr, NULL, NULL, 
-                        &dummy_length, &dummy_flags, 
+  (void)memcached_fetch(ptr, NULL, NULL,
+                        &dummy_length, &dummy_flags,
                         &dummy_error);
   WATCHPOINT_ASSERT(dummy_length == 0);
 
   return value;
 }
 
-memcached_return memcached_mget(memcached_st *ptr, 
-                                const char * const *keys, 
-                                const size_t *key_length, 
+memcached_return memcached_mget(memcached_st *ptr,
+                                const char * const *keys,
+                                const size_t *key_length,
                                 size_t number_of_keys)
 {
   return memcached_mget_by_key(ptr, NULL, 0, keys, key_length, number_of_keys);
@@ -119,16 +119,16 @@ memcached_return memcached_mget(memcached_st *ptr,
 static memcached_return binary_mget_by_key(memcached_st *ptr,
                                            unsigned int master_server_key,
                                            bool is_master_key_set,
-                                           const char * const *keys, 
+                                           const char * const *keys,
                                            const size_t *key_length,
                                            size_t number_of_keys,
                                           bool mget_mode);
 
-static memcached_return memcached_mget_by_key_real(memcached_st *ptr, 
-                                                   const char *master_key, 
+static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
+                                                   const char *master_key,
                                                    size_t master_key_length,
-                                                   const char * const *keys, 
-                                                   const size_t *key_length, 
+                                                   const char * const *keys,
+                                                   const size_t *key_length,
                                                    size_t number_of_keys,
                                                    bool mget_mode)
 {
@@ -162,7 +162,7 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
     is_master_key_set= true;
   }
 
-  /* 
+  /*
     Here is where we pay for the non-block API. We need to remove any data sitting
     in the queue before we start our get.
 
@@ -181,9 +181,9 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
         (void)memcached_response(&ptr->hosts[x], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, &ptr->result);
     }
   }
-  
+
   if (ptr->flags & MEM_BINARY_PROTOCOL)
-    return binary_mget_by_key(ptr, master_server_key, is_master_key_set, keys, 
+    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)
@@ -192,7 +192,7 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
     get_command_length= 5;
   }
 
-  /* 
+  /*
     If a server fails we warn about errors and start all over with sending keys
     to the server.
   */
@@ -267,14 +267,14 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr,
   return rc;
 }
 
-memcached_return memcached_mget_by_key(memcached_st *ptr, 
-                                       const char *master_key, 
+memcached_return memcached_mget_by_key(memcached_st *ptr,
+                                       const char *master_key,
                                        size_t master_key_length,
-                                       const char * const *keys, 
-                                       const size_t *key_length, 
+                                       const char * const *keys,
+                                       const size_t *key_length,
                                        size_t number_of_keys)
 {
-  return memcached_mget_by_key_real(ptr, master_key, master_key_length, keys, 
+  return memcached_mget_by_key_real(ptr, master_key, master_key_length, keys,
                                     key_length, number_of_keys, true);
 }
 
@@ -322,8 +322,8 @@ memcached_return memcached_mget_execute_by_key(memcached_st *ptr,
 static memcached_return simple_binary_mget(memcached_st *ptr,
                                            unsigned int master_server_key,
                                            bool is_master_key_set,
-                                           const char * const *keys, 
-                                           const size_t *key_length, 
+                                           const char * const *keys,
+                                           const size_t *key_length,
                                            size_t number_of_keys, bool mget_mode)
 {
   memcached_return rc= MEMCACHED_NOTFOUND;
@@ -331,11 +331,11 @@ static memcached_return simple_binary_mget(memcached_st *ptr,
 
   int flush= number_of_keys == 1;
 
-  /* 
+  /*
     If a server fails we warn about errors and start all over with sending keys
     to the server.
   */
-  for (x= 0; x < number_of_keys; x++) 
+  for (x= 0; x < number_of_keys; x++)
   {
     unsigned int server_key;
 
@@ -344,13 +344,13 @@ static memcached_return simple_binary_mget(memcached_st *ptr,
     else
       server_key= memcached_generate_hash(ptr, keys[x], key_length[x]);
 
-    if (memcached_server_response_count(&ptr->hosts[server_key]) == 0) 
+    if (memcached_server_response_count(&ptr->hosts[server_key]) == 0)
     {
       rc= memcached_connect(&ptr->hosts[server_key]);
-      if (rc != MEMCACHED_SUCCESS) 
+      if (rc != MEMCACHED_SUCCESS)
         continue;
     }
-     
+
     protocol_binary_request_getk request= {.bytes= {0}};
     request.message.header.request.magic= PROTOCOL_BINARY_REQ;
     if (mget_mode)
@@ -371,26 +371,26 @@ static memcached_return simple_binary_mget(memcached_st *ptr,
     request.message.header.request.keylen= htons((uint16_t)key_length[x]);
     request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
     request.message.header.request.bodylen= htonl((uint32_t) key_length[x]);
-    
+
     if ((memcached_io_write(&ptr->hosts[server_key], request.bytes,
                             sizeof(request.bytes), 0) == -1) ||
-        (memcached_io_write(&ptr->hosts[server_key], keys[x], 
-                            key_length[x], (char) flush) == -1)) 
+        (memcached_io_write(&ptr->hosts[server_key], keys[x],
+                            key_length[x], (char) flush) == -1))
     {
       memcached_server_response_reset(&ptr->hosts[server_key]);
       rc= MEMCACHED_SOME_ERRORS;
       continue;
     }
-    
+
     /* We just want one pending response per server */
-    memcached_server_response_reset(&ptr->hosts[server_key]); 
-    memcached_server_response_increment(&ptr->hosts[server_key]);    
+    memcached_server_response_reset(&ptr->hosts[server_key]);
+    memcached_server_response_increment(&ptr->hosts[server_key]);
     if ((x > 0 && x == ptr->io_key_prefetch) &&
         memcached_flush_buffers(ptr) != MEMCACHED_SUCCESS)
       rc= MEMCACHED_SOME_ERRORS;
   }
 
-  if (mget_mode) 
+  if (mget_mode)
   {
     /*
      * Send a noop command to flush the buffers
@@ -399,19 +399,19 @@ static memcached_return simple_binary_mget(memcached_st *ptr,
     request.message.header.request.magic= PROTOCOL_BINARY_REQ;
     request.message.header.request.opcode= PROTOCOL_BINARY_CMD_NOOP;
     request.message.header.request.datatype= PROTOCOL_BINARY_RAW_BYTES;
-    
+
     for (x= 0; x < ptr->number_of_hosts; x++)
-      if (memcached_server_response_count(&ptr->hosts[x])) 
+      if (memcached_server_response_count(&ptr->hosts[x]))
       {
-        if (memcached_io_write(&ptr->hosts[x], NULL, 0, 1) == -1) 
+        if (memcached_io_write(&ptr->hosts[x], NULL, 0, 1) == -1)
         {
           memcached_server_response_reset(&ptr->hosts[x]);
           memcached_io_reset(&ptr->hosts[x]);
           rc= MEMCACHED_SOME_ERRORS;
         }
 
-        if (memcached_io_write(&ptr->hosts[x], request.bytes, 
-                              sizeof(request.bytes), 1) == -1) 
+        if (memcached_io_write(&ptr->hosts[x], request.bytes,
+                              sizeof(request.bytes), 1) == -1)
         {
           memcached_server_response_reset(&ptr->hosts[x]);
           memcached_io_reset(&ptr->hosts[x]);
@@ -425,9 +425,9 @@ static memcached_return simple_binary_mget(memcached_st *ptr,
 }
 
 static memcached_return replication_binary_mget(memcached_st *ptr,
-                                                uint32_t* hash, 
+                                                uint32_t* hash,
                                                 bool* dead_servers,
-                                                const char *const *keys, 
+                                                const char *const *keys,
                                                 const size_t *key_length,
                                                 size_t number_of_keys)
 {
@@ -435,14 +435,14 @@ static memcached_return replication_binary_mget(memcached_st *ptr,
   uint32_t x, start= 0;
   uint64_t randomize_read= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ);
 
-  if (randomize_read) 
-    start= (uint32_t)(random() % (ptr->number_of_replicas + 1));
+  if (randomize_read)
+     start= (uint32_t)random() % (uint32_t)(ptr->number_of_replicas + 1);
 
   /* Loop for each replica */
   for (uint32_t replica= 0; replica <= ptr->number_of_replicas; ++replica)
   {
     bool success= true;
+
     for (x= 0; x < number_of_keys; ++x)
     {
       if (hash[x] == ptr->number_of_hosts)
@@ -453,7 +453,7 @@ static memcached_return replication_binary_mget(memcached_st *ptr,
       /* In case of randomized reads */
       if (randomize_read && ((server + start) <= (hash[x] + ptr->number_of_replicas)))
         server += start;
-      
+
       while (server >= ptr->number_of_hosts)
         server -= ptr->number_of_hosts;
 
@@ -517,19 +517,19 @@ static memcached_return replication_binary_mget(memcached_st *ptr,
 static memcached_return binary_mget_by_key(memcached_st *ptr,
                                            unsigned int master_server_key,
                                            bool is_master_key_set,
-                                           const char * const *keys, 
+                                           const char * const *keys,
                                            const size_t *key_length,
-                                           size_t number_of_keys, 
+                                           size_t number_of_keys,
                                            bool mget_mode)
 {
   memcached_return rc;
 
-  if (ptr->number_of_replicas == 0) 
+  if (ptr->number_of_replicas == 0)
   {
     rc= simple_binary_mget(ptr, master_server_key, is_master_key_set,
                            keys, key_length, number_of_keys, mget_mode);
-  } 
-  else 
+  }
+  else
   {
     uint32_t* hash;
     bool* dead_servers;
@@ -551,7 +551,7 @@ static memcached_return binary_mget_by_key(memcached_st *ptr,
       for (unsigned int x= 0; x < number_of_keys; x++)
         hash[x]= memcached_generate_hash(ptr, keys[x], key_length[x]);
 
-    rc= replication_binary_mget(ptr, hash, dead_servers, keys, 
+    rc= replication_binary_mget(ptr, hash, dead_servers, keys,
                                 key_length, number_of_keys);
 
     ptr->call_free(ptr, hash);