configure: modern c++ flags; suppress some libmemcached warnings
[awesomized/libmemcached] / clients / memping.cc
index f4fcec861a34e06d6b9701c298785c5dffd5331c..180d6a2108eee67450c42401cfd61cf9355432a9 100644 (file)
@@ -9,12 +9,14 @@
  * Summary:
  *
  */
-#include "config.h"
+#include "mem_config.h"
 
-#include <stdio.h>
-#include <unistd.h>
-#include <string.h>
+#include <cerrno>
+#include <cstdio>
+#include <cstring>
 #include <getopt.h>
+#include <unistd.h>
+
 #include <libmemcached-1.0/memcached.h>
 #include <libmemcachedutil-1.0/util.h>
 #include "client_options.h"
@@ -47,7 +49,8 @@ int main(int argc, char *argv[])
     {
       opt_servers= strdup(temp);
     }
-    else
+    
+    if (opt_servers == NULL)
     {
       std::cerr << "No Servers provided" << std::endl;
       exit(EXIT_FAILURE);
@@ -56,6 +59,12 @@ int main(int argc, char *argv[])
 
   int exit_code= EXIT_SUCCESS;
   memcached_server_st *servers= memcached_servers_parse(opt_servers);
+  if (servers == NULL or memcached_server_list_count(servers) == 0)
+  {
+    std::cerr << "Invalid server list provided:" << opt_servers << std::endl;
+    exit_code= EXIT_FAILURE;
+  }
+  else
   {
     for (uint32_t x= 0; x < memcached_server_list_count(servers); x++)
     {
@@ -63,6 +72,11 @@ int main(int argc, char *argv[])
       const char *hostname= servers[x].hostname;
       in_port_t port= servers[x].port;
 
+      if (opt_verbose)
+      {
+        std::cout << "Trying to ping " << hostname << ":" << port << std::endl;
+      }
+
       if (libmemcached_util_ping2(hostname, port, opt_username, opt_passwd, &instance_rc) == false)
       {
         std::cerr << "Failed to ping " << hostname << ":" << port << " " << memcached_strerror(NULL, instance_rc) <<  std::endl;
@@ -139,11 +153,18 @@ void options_parse(int argc, char *argv[])
       break;
 
     case OPT_EXPIRE: /* --expire */
-      opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+      errno= 0;
+      opt_expire= time_t(strtoll(optarg, (char **)NULL, 10));
+      if (errno != 0)
+      {
+        std::cerr << "Incorrect value passed to --expire: `" << optarg << "`" << std::endl;
+        exit(EXIT_FAILURE);
+      }
       break;
 
     case OPT_USERNAME:
       opt_username= optarg;
+      opt_binary= true;
       break;
 
     case OPT_PASSWD: