*/
#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"
{
opt_servers= strdup(temp);
}
- else
+
+ if (opt_servers == NULL)
{
std::cerr << "No Servers provided" << std::endl;
exit(EXIT_FAILURE);
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++)
{
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;
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: