cppcheck warnings fixed.
[m6w6/libmemcached] / clients / ms_setting.c
index 95af535c74c89e0212670c43c1b88acc1da8b745..3eb4d0e6e9d9a79668f91aef06512864a46de338 100644 (file)
@@ -19,7 +19,6 @@
 #include <pwd.h>
 #include <strings.h>
 #include <sys/types.h>
-#include <sys/types.h>
 #include <unistd.h>
 
 
@@ -54,7 +53,7 @@ ms_setting_st ms_setting;       /* store the settings specified by user */
 
 /* read setting from configuration file */
 static void ms_get_serverlist(char *str);
-static int ms_get_cpu_count(void);
+static uint32_t ms_get_cpu_count(void);
 ms_conf_type_t ms_get_conf_type(char *line);
 static int ms_is_line_data(char *line);
 static int ms_read_is_data(char *line, ssize_t nread);
@@ -196,9 +195,9 @@ static void ms_get_serverlist(char *str)
 /**
  * used to get the CPU count of the current system
  *
- * @return return the cpu count if get, else return 1
+ * @return return the cpu count if get, else return EXIT_FAILURE
  */
-static int ms_get_cpu_count()
+static uint32_t ms_get_cpu_count()
 {
 #ifdef HAVE__SC_NPROCESSORS_ONLN
   return sysconf(_SC_NPROCESSORS_CONF);
@@ -224,7 +223,7 @@ static int ms_get_cpu_count()
 #endif
 
   /* the system with one cpu at least */
-  return 1;
+  return EXIT_FAILURE;
 } /* ms_get_cpu_count */
 
 
@@ -263,7 +262,7 @@ ms_conf_type_t ms_get_conf_type(char *line)
  *
  * @param line, string of one line
  *
- * @return if success, return 1, else return 0
+ * @return if success, return EXIT_FAILURE, else return EXIT_SUCCESS
  */
 static int ms_is_line_data(char *line)
 {
@@ -276,9 +275,9 @@ static int ms_is_line_data(char *line)
     begin_ptr++;
   }
   if ((begin_ptr[0] == '\0') || (begin_ptr[0] == '#'))
-    return 0;
+    return EXIT_SUCCESS;
 
-  return 1;
+  return EXIT_FAILURE;
 } /* ms_is_line_data */
 
 
@@ -288,14 +287,14 @@ static int ms_is_line_data(char *line)
  * @param line, string of one line
  * @param nread, length of the line
  *
- * @return if it's EOF or not line data, return 0, else return 1
+ * @return if it's EOF or not line data, return EXIT_SUCCESS, else return EXIT_FAILURE
  */
 static int ms_read_is_data(char *line, ssize_t nread)
 {
   if ((nread == EOF) || ! ms_is_line_data(line))
-    return 0;
+    return EXIT_SUCCESS;
 
-  return 1;
+  return EXIT_FAILURE;
 } /* ms_read_is_data */
 
 
@@ -342,7 +341,6 @@ static void ms_parse_cfg_file(char *cfg_file)
   FILE *f;
   size_t start_len, end_len;
   double proportion;
-  size_t frequence;
   char *line= NULL;
   size_t  read_len;
   ssize_t nread;
@@ -435,8 +433,8 @@ static void ms_parse_cfg_file(char *cfg_file)
 
         if (nread != EOF)
         {
-          if (sscanf(line, "%zu %zu %lf %zu", &start_len, &end_len,
-                     &proportion, &frequence) != 3)
+          if (sscanf(line, "%zu %zu %lf", &start_len, &end_len,
+                     &proportion) != 3)
           {
             conf_type= ms_get_conf_type(line);
             break;
@@ -479,11 +477,15 @@ static void ms_parse_cfg_file(char *cfg_file)
 
         if (nread != EOF)
         {
-          if (sscanf(line, "%d %lf\n", &cmd_type, &proportion) != 2)
+          if (sscanf(line, "%d %lf", &cmd_type, &proportion) != 2)
           {
             conf_type= ms_get_conf_type(line);
             break;
           }
+          if (cmd_type >= CMD_NULL)
+          {
+            continue;
+          }
           ms_setting.cmd_distr[ms_setting.cmd_used_count].cmd_type=
             cmd_type;
           ms_setting.cmd_distr[ms_setting.cmd_used_count].cmd_prop=
@@ -573,7 +575,7 @@ static void ms_calc_avg_size()
  * @param distr, pointer of distribution structure array
  * @param length, length of the array
  *
- * @return always return 0
+ * @return always return EXIT_SUCCESS
  */
 static int ms_shuffle_distr(ms_distr_t *distr, int length)
 {
@@ -612,7 +614,7 @@ static int ms_shuffle_distr(ms_distr_t *distr, int length)
     } /* switch */
   }
 
-  return 0;
+  return EXIT_SUCCESS;
 } /* ms_shuffle_distr */
 
 
@@ -681,7 +683,7 @@ static void ms_build_distr()
         exit(1);
       }
 
-      if (! ms_setting.binary_prot
+      if (! ms_setting.binary_prot_
           && ((start_len > MAX_KEY_SIZE) || (end_len > MAX_KEY_SIZE)))
       {
         fprintf(stderr, "key length must be less than 250 bytes.\n");
@@ -878,7 +880,7 @@ static void ms_setting_slapmode_init_pre()
   ms_setting.reconnect= false;
   ms_setting.verbose= false;
   ms_setting.facebook_test= false;
-  ms_setting.binary_prot= false;
+  ms_setting.binary_prot_= false;
   ms_setting.stat_freq= 0;
   ms_setting.srv_str= NULL;
   ms_setting.cfg_file= NULL;
@@ -920,7 +922,7 @@ void ms_setting_init_pre()
 static void ms_setting_slapmode_init_post()
 {
   ms_setting.total_key_rng_cnt= KEY_RANGE_COUNT_INIT;
-  ms_setting.key_distr= 
+  ms_setting.key_distr=
     (ms_key_distr_t *)malloc((size_t)ms_setting.total_key_rng_cnt * sizeof(ms_key_distr_t));
 
   if (ms_setting.key_distr == NULL)
@@ -931,7 +933,7 @@ static void ms_setting_slapmode_init_post()
 
   ms_setting.total_val_rng_cnt= VALUE_RANGE_COUNT_INIT;
 
-  ms_setting.value_distr= 
+  ms_setting.value_distr=
     (ms_value_distr_t *)malloc((size_t)ms_setting.total_val_rng_cnt * sizeof( ms_value_distr_t));
 
   if (ms_setting.value_distr == NULL)
@@ -980,13 +982,6 @@ static void ms_setting_slapmode_init_post()
     exit(1);
   }
 
-  if ((ms_setting.udp
-       || ms_setting.facebook_test) && ms_setting.binary_prot)
-  {
-    fprintf(stderr, "Binary protocol doesn't support UDP now.\n");
-    exit(1);
-  }
-
   if ((ms_setting.rep_write_srv > 0) && (ms_setting.srv_cnt < 2))
   {
     fprintf(stderr, "Please specify 2 servers at least for replication\n");
@@ -1007,26 +1002,12 @@ static void ms_setting_slapmode_init_post()
     exit(1);
   }
 
-  if ((ms_setting.rep_write_srv > 0) && (ms_setting.sock_per_conn > 1))
-  {
-    fprintf(stderr, "Replication doesn't support multi-socks "
-                    "in one connection structure.\n");
-    exit(1);
-  }
-
   if (ms_setting.facebook_test && (ms_setting.rep_write_srv > 0))
   {
     fprintf(stderr, "facebook test couldn't work with replication.\n");
     exit(1);
   }
 
-  if (ms_setting.reconnect && (ms_setting.sock_per_conn > 1))
-  {
-    fprintf(stderr, "Reconnection doesn't support multi-socks "
-                    "in one connection structure.\n");
-    exit(1);
-  }
-
   ms_build_distr();
 
   /* initialize global character block */