*/
#include "config.h"
-#include <stdio.h>
-#include <unistd.h>
+#include <cstdio>
+#include <cstring>
#include <getopt.h>
+#include <iostream>
+#include <unistd.h>
+
#include <libmemcached/memcached.h>
-#include <string.h>
#include "client_options.h"
#include "utilities.h"
options_parse(argc, argv);
initialize_sockets();
- if (!opt_servers)
+ if (opt_servers == 0)
{
char *temp;
opt_servers= strdup(temp);
else
{
- fprintf(stderr, "No Servers provided\n");
- exit(1);
+ std::cerr << "No Servers provided" << std::endl;
+ return EXIT_FAILURE;
}
}
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL,
(uint64_t) opt_binary);
- if (!initialize_sasl(memc, opt_username, opt_passwd))
+ if (opt_username and LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
{
memcached_free(memc);
+ std::cerr << "--username was supplied, but binary was not built with SASL support." << std::endl;
return EXIT_FAILURE;
}
+ if (opt_username)
+ {
+ memcached_return_t ret;
+ if (memcached_failed(ret= memcached_set_sasl_auth_data(memc, opt_username, opt_passwd)))
+ {
+ std::cerr << memcached_last_error_message(memc) << std::endl;
+ memcached_free(memc);
+ return EXIT_FAILURE;
+ }
+ }
+
while (optind < argc)
{
if (opt_verbose)
- printf("key: %s\nexpires: %llu\n", argv[optind], (unsigned long long)opt_expire);
- rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire);
+ {
+ std::cout << "key: " << argv[optind] << std::endl;
+ std::cout << "expires: " << opt_expire << std::endl;
+ }
+ rc= memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire);
- if (rc != MEMCACHED_SUCCESS)
+ if (memcached_failed(rc))
{
- fprintf(stderr, "memrm: %s: memcache error %s",
- argv[optind], memcached_strerror(memc, rc));
+ std::cerr << PROGRAM_NAME << ": " << argv[optind] << ": error " << memcached_strerror(memc, rc) << std::endl;
+
if (memcached_last_error_errno(memc))
- fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc)));
- fprintf(stderr, "\n");
+ {
+ std::cerr << " system error " << strerror(memcached_last_error_errno(memc));
+ }
+ std::cerr << std::endl;
return_code= -1;
}
if (opt_hash)
free(opt_hash);
- shutdown_sasl();
-
return return_code;
}