cppcheck warnings fixed.
[m6w6/libmemcached] / clients / ms_conn.c
index 32578b3e920323d34547b1d1133b44d30272eb3b..b4d5f673d11df8ce616ec7494f1c3a4dc49faf76 100644 (file)
@@ -18,6 +18,7 @@
 #include <event.h>
 #include <fcntl.h>
 #include <netinet/tcp.h>
+#include <netinet/in.h>
 #include <arpa/inet.h>
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
@@ -130,8 +131,8 @@ static int ms_transmit(ms_conn_t *c);
 static void ms_conn_shrink(ms_conn_t *c);
 static void ms_conn_set_state(ms_conn_t *c, int state);
 static bool ms_update_event(ms_conn_t *c, const int new_flags);
-static int ms_get_rep_sock_index(ms_conn_t *c, int cmd);
-static int ms_get_next_sock_index(ms_conn_t *c);
+static uint32_t ms_get_rep_sock_index(ms_conn_t *c, int cmd);
+static uint32_t ms_get_next_sock_index(ms_conn_t *c);
 static int ms_update_conn_sock_event(ms_conn_t *c);
 static bool ms_need_yield(ms_conn_t *c);
 static void ms_update_start_time(ms_conn_t *c);
@@ -223,7 +224,7 @@ static void ms_task_init(ms_conn_t *c)
  * @param c, pointer of the concurrency
  * @param is_udp, whether it's udp
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_conn_udp_init(ms_conn_t *c, const bool is_udp)
 {
@@ -259,7 +260,7 @@ static int ms_conn_udp_init(ms_conn_t *c, const bool is_udp)
     memset(c->udppkt, 0, MAX_UDP_PACKET * sizeof(ms_udppkt_t));
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_conn_udp_init */
 
 
@@ -271,7 +272,7 @@ static int ms_conn_udp_init(ms_conn_t *c, const bool is_udp)
  * @param read_buffer_size
  * @param is_udp, whether it's udp
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_conn_init(ms_conn_t *c,
                         const int init_state,
@@ -357,7 +358,7 @@ static int ms_conn_init(ms_conn_t *c,
   c->mlget_task.mlget_num= 0;
   c->mlget_task.value_index= -1;         /* default invalid value */
 
-  if (ms_setting.binary_prot)
+  if (ms_setting.binary_prot_)
   {
     c->protocol= binary_prot;
   }
@@ -380,7 +381,7 @@ static int ms_conn_init(ms_conn_t *c,
     atomic_add_32(&ms_stats.active_conns, 1);
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_conn_init */
 
 
@@ -413,7 +414,7 @@ static void ms_warmup_num_init(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_item_win_init(ms_conn_t *c)
 {
@@ -457,7 +458,7 @@ static int ms_item_win_init(ms_conn_t *c)
 
   ms_warmup_num_init(c);
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_item_win_init */
 
 
@@ -468,14 +469,14 @@ static int ms_item_win_init(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_conn_sock_init(ms_conn_t *c)
 {
   ms_thread_t *ms_thread= pthread_getspecific(ms_thread_key);
-  int i;
+  uint32_t i;
   int ret_sfd;
-  int srv_idx= 0;
+  uint32_t srv_idx= 0;
 
   assert(c != NULL);
   assert(c->tcpsfd != NULL);
@@ -538,7 +539,7 @@ static int ms_conn_sock_init(ms_conn_t *c)
     }
     else
     {
-      for (int j= 0; j < i; j++)
+      for (uint32_t j= 0; j < i; j++)
       {
         close(c->tcpsfd[j]);
       }
@@ -552,7 +553,7 @@ static int ms_conn_sock_init(ms_conn_t *c)
     return -1;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_conn_sock_init */
 
 
@@ -562,7 +563,7 @@ static int ms_conn_sock_init(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_conn_event_init(ms_conn_t *c)
 {
@@ -578,7 +579,7 @@ static int ms_conn_event_init(ms_conn_t *c)
     return -1;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_conn_event_init */
 
 
@@ -588,7 +589,7 @@ static int ms_conn_event_init(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 int ms_setup_conn(ms_conn_t *c)
 {
@@ -612,7 +613,7 @@ int ms_setup_conn(ms_conn_t *c)
     return -1;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_setup_conn */
 
 
@@ -668,7 +669,7 @@ static void ms_conn_close(ms_conn_t *c)
   /* delete the event, the socket and the connection */
   event_del(&c->event);
 
-  for (int i= 0; i < c->total_sfds; i++)
+  for (uint32_t i= 0; i < c->total_sfds; i++)
   {
     if (c->tcpsfd[i] > 0)
     {
@@ -706,7 +707,7 @@ static void ms_conn_close(ms_conn_t *c)
  *
  * @param ai, server address information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_new_socket(struct addrinfo *ai)
 {
@@ -770,7 +771,7 @@ static void ms_maximize_sndbuf(const int sfd)
  * @param is_udp, whether it's udp
  * @param ret_sfd, the connected socket file descriptor
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_network_connect(ms_conn_t *c,
                               char *srv_host_name,
@@ -797,7 +798,11 @@ static int ms_network_connect(ms_conn_t *c,
    * that otherwise mess things up.
    */
   memset(&hints, 0, sizeof(hints));
+#ifdef AI_ADDRCONFIG
   hints.ai_flags= AI_PASSIVE | AI_ADDRCONFIG;
+#else
+  hints.ai_flags= AI_PASSIVE;
+#endif /* AI_ADDRCONFIG */
   if (is_udp)
   {
     hints.ai_protocol= IPPROTO_UDP;
@@ -889,23 +894,23 @@ static int ms_network_connect(ms_conn_t *c,
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_reconn(ms_conn_t *c)
 {
   ms_thread_t *ms_thread= pthread_getspecific(ms_thread_key);
-  int srv_idx= 0;
-  int32_t srv_conn_cnt= 0;
+  uint32_t srv_idx= 0;
+  uint32_t srv_conn_cnt= 0;
 
   if (ms_setting.rep_write_srv > 0)
   {
     srv_idx= c->cur_idx % ms_setting.srv_cnt;
-    srv_conn_cnt= (int)(ms_setting.sock_per_conn  * ms_setting.nconns);
+    srv_conn_cnt= ms_setting.sock_per_conn  * ms_setting.nconns;
   }
   else
   {
     srv_idx= ms_thread->thread_ctx->srv_idx;
-    srv_conn_cnt= (int32_t)((int)ms_setting.nconns / ms_setting.srv_cnt);
+    srv_conn_cnt= ms_setting.nconns / ms_setting.srv_cnt;
   }
 
   /* close the old socket handler */
@@ -913,7 +918,7 @@ static int ms_reconn(ms_conn_t *c)
   c->tcpsfd[c->cur_idx]= 0;
 
   if (atomic_add_32_nv(&ms_setting.servers[srv_idx].disconn_cnt, 1)
-      % (uint32_t)srv_conn_cnt == 0)
+      % srv_conn_cnt == 0)
   {
     gettimeofday(&ms_setting.servers[srv_idx].disconn_time, NULL);
     fprintf(stderr, "Server %s:%d disconnect\n",
@@ -923,7 +928,8 @@ static int ms_reconn(ms_conn_t *c)
 
   if (ms_setting.rep_write_srv > 0)
   {
-    int i= 0;
+    uint32_t i= 0;
+
     for (i= 0; i < c->total_sfds; i++)
     {
       if (c->tcpsfd[i] != 0)
@@ -978,7 +984,7 @@ static int ms_reconn(ms_conn_t *c)
     c->alive_sfds--;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_reconn */
 
 
@@ -990,24 +996,24 @@ static int ms_reconn(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 int ms_reconn_socks(ms_conn_t *c)
 {
   ms_thread_t *ms_thread= pthread_getspecific(ms_thread_key);
-  int srv_idx= 0;
+  uint32_t srv_idx= 0;
   int ret_sfd= 0;
-  int srv_conn_cnt= 0;
+  uint32_t srv_conn_cnt= 0;
   struct timeval cur_time;
 
   assert(c != NULL);
 
   if ((c->total_sfds == 1) || (c->total_sfds == c->alive_sfds))
   {
-    return 0;
+    return EXIT_SUCCESS;
   }
 
-  for (int i= 0; i < c->total_sfds; i++)
+  for (uint32_t i= 0; i < c->total_sfds; i++)
   {
     if (c->tcpsfd[i] == 0)
     {
@@ -1028,12 +1034,12 @@ int ms_reconn_socks(ms_conn_t *c)
       if (ms_setting.rep_write_srv > 0)
       {
         srv_idx= i % ms_setting.srv_cnt;
-        srv_conn_cnt= (int)(ms_setting.sock_per_conn * ms_setting.nconns);
+        srv_conn_cnt= ms_setting.sock_per_conn * ms_setting.nconns;
       }
       else
       {
         srv_idx= ms_thread->thread_ctx->srv_idx;
-        srv_conn_cnt= (int)ms_setting.nconns / ms_setting.srv_cnt;
+        srv_conn_cnt= ms_setting.nconns / ms_setting.srv_cnt;
       }
 
       if (ms_network_connect(c, ms_setting.servers[srv_idx].srv_host_name,
@@ -1059,7 +1065,7 @@ int ms_reconn_socks(ms_conn_t *c)
     }
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_reconn_socks */
 
 
@@ -1131,7 +1137,7 @@ static int ms_tokenize_command(char *command,
  * @param c, pointer of the concurrency
  * @param command, the string responded by server
  *
- * @return int, if the command completed return 0, else return
+ * @return int, if the command completed return EXIT_SUCCESS, else return
  *         -1
  */
 static int ms_ascii_process_line(ms_conn_t *c, char *command)
@@ -1306,7 +1312,7 @@ void ms_reset_conn(ms_conn_t *c, bool timeout)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_try_read_line(ms_conn_t *c)
 {
@@ -1316,7 +1322,7 @@ static int ms_try_read_line(ms_conn_t *c)
     if ((uint64_t)c->rbytes < sizeof(c->binary_header))
     {
       /* need more data! */
-      return 0;
+      return EXIT_SUCCESS;
     }
     else
     {
@@ -1346,7 +1352,7 @@ static int ms_try_read_line(ms_conn_t *c)
         fprintf(stderr, "Invalid magic:  %x\n",
                 c->binary_header.response.magic);
         ms_conn_set_state(c, conn_closing);
-        return 0;
+        return EXIT_SUCCESS;
       }
 
       /* process this complete response */
@@ -1371,11 +1377,11 @@ static int ms_try_read_line(ms_conn_t *c)
     assert(c->rcurr <= (c->rbuf + c->rsize));
 
     if (c->rbytes == 0)
-      return 0;
+      return EXIT_SUCCESS;
 
     el= memchr(c->rcurr, '\n', (size_t)c->rbytes);
     if (! el)
-      return 0;
+      return EXIT_SUCCESS;
 
     cont= el + 1;
     if (((el - c->rcurr) > 1) && (*(el - 1) == '\r'))
@@ -1629,7 +1635,7 @@ static int ms_udp_read(ms_conn_t *c, char *buf, int len)
  * close.
  * before reading, move the remaining incomplete fragment of a command
  * (if any) to the beginning of the buffer.
- * return 0 if there's nothing to read on the first read.
+ * return EXIT_SUCCESS if there's nothing to read on the first read.
  */
 
 /**
@@ -1640,8 +1646,8 @@ static int ms_udp_read(ms_conn_t *c, char *buf, int len)
  * @param c, pointer of the concurrency
  *
  * @return int,
- *         return 0 if there's nothing to read on the first read.
- *         return 1 if get data
+ *         return EXIT_SUCCESS if there's nothing to read on the first read.
+ *         return EXIT_FAILURE if get data
  *         return -1 if error happens
  */
 static int ms_try_read_network(ms_conn_t *c)
@@ -2007,7 +2013,7 @@ static void ms_complete_nread(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_add_msghdr(ms_conn_t *c)
 {
@@ -2051,7 +2057,7 @@ static int ms_add_msghdr(ms_conn_t *c)
     return ms_add_iov(c, NULL, UDP_HEADER_SIZE);
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_add_msghdr */
 
 
@@ -2061,7 +2067,7 @@ static int ms_add_msghdr(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_ensure_iov_space(ms_conn_t *c)
 {
@@ -2088,7 +2094,7 @@ static int ms_ensure_iov_space(ms_conn_t *c)
     }
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_ensure_iov_space */
 
 
@@ -2100,7 +2106,7 @@ static int ms_ensure_iov_space(ms_conn_t *c)
  * @param buf, the buffer includes data to send
  * @param len, the data length in the buffer
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_add_iov(ms_conn_t *c, const void *buf, int len)
 {
@@ -2119,6 +2125,7 @@ static int ms_add_iov(ms_conn_t *c, const void *buf, int len)
      */
     limit_to_mtu= c->udp;
 
+#ifdef IOV_MAX
     /* We may need to start a new msghdr if this one is full. */
     if ((m->msg_iovlen == IOV_MAX)
         || (limit_to_mtu && (c->msgbytes >= UDP_MAX_SEND_PAYLOAD_SIZE)))
@@ -2126,6 +2133,7 @@ static int ms_add_iov(ms_conn_t *c, const void *buf, int len)
       ms_add_msghdr(c);
       m= &c->msglist[c->msgused - 1];
     }
+#endif
 
     if (ms_ensure_iov_space(c) != 0)
       return -1;
@@ -2154,7 +2162,7 @@ static int ms_add_iov(ms_conn_t *c, const void *buf, int len)
   }
   while (leftover > 0);
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_add_iov */
 
 
@@ -2163,7 +2171,7 @@ static int ms_add_iov(ms_conn_t *c, const void *buf, int len)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_udp_headers(ms_conn_t *c)
 {
@@ -2214,7 +2222,7 @@ static int ms_build_udp_headers(ms_conn_t *c)
             + UDP_HEADER_SIZE));
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_udp_headers */
 
 
@@ -2459,9 +2467,7 @@ static bool ms_need_yield(ms_conn_t *c)
   {
     gettimeofday(&curr_time, NULL);
     time_diff= ms_time_diff(&ms_thread->startup_time, &curr_time);
-    tps=
-      (int64_t)((task->get_opt
-                 + task->set_opt) / ((uint64_t)time_diff / 1000000));
+    tps= (int64_t)(((task->get_opt + task->set_opt) / (uint64_t)time_diff) * 1000000);
 
     /* current throughput is greater than expected throughput */
     if (tps > ms_thread->thread_ctx->tps_perconn)
@@ -2719,16 +2725,16 @@ void ms_event_handler(const int fd, const short which, void *arg)
  * @param c, pointer of the concurrency
  * @param cmd, command(get or set )
  *
- * @return int, if success, return the index, else return 0
+ * @return int, if success, return the index, else return EXIT_SUCCESS
  */
-static int ms_get_rep_sock_index(ms_conn_t *c, int cmd)
+static uint32_t ms_get_rep_sock_index(ms_conn_t *c, int cmd)
 {
-  int sock_index= -1;
-  int i= 0;
+  uint32_t sock_index= 0;
+  uint32_t i= 0;
 
   if (c->total_sfds == 1)
   {
-    return 0;
+    return EXIT_SUCCESS;
   }
 
   if (ms_setting.rep_write_srv == 0)
@@ -2751,18 +2757,18 @@ static int ms_get_rep_sock_index(ms_conn_t *c, int cmd)
       if (i == ms_setting.rep_write_srv)
       {
         /* random get one replication server to read */
-        sock_index= (int)(random() % c->total_sfds);
+        sock_index= (uint32_t)random() % c->total_sfds;
       }
       else
       {
         /* random get one replication writing server to write */
-        sock_index= (int)(random() % ms_setting.rep_write_srv);
+        sock_index= (uint32_t)random() % ms_setting.rep_write_srv;
       }
     }
     else if (cmd == CMD_GET)
     {
       /* random get one replication server to read */
-      sock_index= (int)(random() % c->total_sfds);
+      sock_index= (uint32_t)random() % c->total_sfds;
     }
   }
   while (c->tcpsfd[sock_index] == 0);
@@ -2778,9 +2784,9 @@ static int ms_get_rep_sock_index(ms_conn_t *c, int cmd)
  *
  * @return int, return the index
  */
-static int ms_get_next_sock_index(ms_conn_t *c)
+static uint32_t ms_get_next_sock_index(ms_conn_t *c)
 {
-  int sock_index= 0;
+  uint32_t sock_index= 0;
 
   do
   {
@@ -2797,7 +2803,7 @@ static int ms_get_next_sock_index(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_update_conn_sock_event(ms_conn_t *c)
 {
@@ -2861,7 +2867,7 @@ static int ms_update_conn_sock_event(ms_conn_t *c)
     }
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_update_conn_sock_event */
 
 
@@ -2873,7 +2879,7 @@ static int ms_update_conn_sock_event(ms_conn_t *c)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_ascii_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
 {
@@ -2881,13 +2887,14 @@ static int ms_build_ascii_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
   int write_len;
   char *buffer= c->wbuf;
 
-  write_len= sprintf(buffer,
-                     " %u %d %d\r\n",
-                     0,
-                     item->exp_time,
-                     item->value_size);
+  write_len= snprintf(buffer,
+                      c->wsize,
+                      " %u %d %d\r\n",
+                      0,
+                      item->exp_time,
+                      item->value_size);
 
-  if (write_len > c->wsize)
+  if (write_len > c->wsize || write_len < 0)
   {
     /* ought to be always enough. just fail for simplicity */
     fprintf(stderr, "output command line too long.\n");
@@ -2917,7 +2924,7 @@ static int ms_build_ascii_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
     return -1;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_ascii_write_buf_set */
 
 
@@ -2928,7 +2935,7 @@ static int ms_build_ascii_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 int ms_mcd_set(ms_conn_t *c, ms_task_item_t *item)
 {
@@ -2972,7 +2979,7 @@ int ms_mcd_set(ms_conn_t *c, ms_task_item_t *item)
                   item->key_size + item->value_size);
   atomic_add_size(&ms_stats.cmd_set, 1);
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_mcd_set */
 
 
@@ -2984,7 +2991,7 @@ int ms_mcd_set(ms_conn_t *c, ms_task_item_t *item)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_ascii_write_buf_get(ms_conn_t *c, ms_task_item_t *item)
 {
@@ -2999,7 +3006,7 @@ static int ms_build_ascii_write_buf_get(ms_conn_t *c, ms_task_item_t *item)
     return -1;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_ascii_write_buf_get */
 
 
@@ -3010,7 +3017,7 @@ static int ms_build_ascii_write_buf_get(ms_conn_t *c, ms_task_item_t *item)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 int ms_mcd_get(ms_conn_t *c, ms_task_item_t *item)
 {
@@ -3052,7 +3059,7 @@ int ms_mcd_get(ms_conn_t *c, ms_task_item_t *item)
 
   atomic_add_size(&ms_stats.cmd_get, 1);
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_mcd_get */
 
 
@@ -3062,7 +3069,7 @@ int ms_mcd_get(ms_conn_t *c, ms_task_item_t *item)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_ascii_write_buf_mlget(ms_conn_t *c)
 {
@@ -3093,7 +3100,7 @@ static int ms_build_ascii_write_buf_mlget(ms_conn_t *c)
     return -1;
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_ascii_write_buf_mlget */
 
 
@@ -3102,7 +3109,7 @@ static int ms_build_ascii_write_buf_mlget(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 int ms_mcd_mlget(ms_conn_t *c)
 {
@@ -3152,7 +3159,7 @@ int ms_mcd_mlget(ms_conn_t *c)
     atomic_add_size(&ms_stats.cmd_get, 1);
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_mcd_mlget */
 
 
@@ -3165,7 +3172,7 @@ int ms_mcd_mlget(ms_conn_t *c)
  *
  * @param c, pointer of the concurrency
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_bin_process_response(ms_conn_t *c)
 {
@@ -3181,7 +3188,7 @@ static int ms_bin_process_response(ms_conn_t *c)
   {
     c->rvbytes= (int32_t)bodylen;
     c->readval= true;
-    return 1;
+    return EXIT_FAILURE;
   }
   else
   {
@@ -3248,7 +3255,7 @@ static int ms_bin_process_response(ms_conn_t *c)
     }
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_bin_process_response */
 
 
@@ -3281,7 +3288,7 @@ static void ms_add_bin_header(ms_conn_t *c,
 
   header->request.extlen= (uint8_t)hdr_len;
   header->request.datatype= (uint8_t)PROTOCOL_BINARY_RAW_BYTES;
-  header->request.reserved= 0;
+  header->request.vbucket= 0;
 
   header->request.bodylen= htonl(body_len);
   header->request.opaque= 0;
@@ -3314,7 +3321,7 @@ static void ms_add_key_to_iov(ms_conn_t *c, ms_task_item_t *item)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_bin_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
 {
@@ -3346,7 +3353,7 @@ static int ms_build_bin_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
   }
   ms_add_iov(c, &ms_setting.char_block[value_offset], item->value_size);
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_bin_write_buf_set */
 
 
@@ -3358,7 +3365,7 @@ static int ms_build_bin_write_buf_set(ms_conn_t *c, ms_task_item_t *item)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_bin_write_buf_get(ms_conn_t *c, ms_task_item_t *item)
 {
@@ -3368,7 +3375,7 @@ static int ms_build_bin_write_buf_get(ms_conn_t *c, ms_task_item_t *item)
                     (uint32_t)item->key_size);
   ms_add_key_to_iov(c, item);
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_bin_write_buf_get */
 
 
@@ -3380,7 +3387,7 @@ static int ms_build_bin_write_buf_get(ms_conn_t *c, ms_task_item_t *item)
  * @param item, pointer of task item which includes the object
  *            information
  *
- * @return int, if success, return 0, else return -1
+ * @return int, if success, return EXIT_SUCCESS, else return -1
  */
 static int ms_build_bin_write_buf_mlget(ms_conn_t *c)
 {
@@ -3404,5 +3411,5 @@ static int ms_build_bin_write_buf_mlget(ms_conn_t *c)
 
   c->wcurr= c->wbuf;
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_build_bin_write_buf_mlget */