projects
/
awesomized
/
libmemcached
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
|
github
raw
|
inline
| side by side
bootstrap: add arch linux
[awesomized/libmemcached]
/
clients
/
memcat.cc
diff --git
a/clients/memcat.cc
b/clients/memcat.cc
index ab482e5d6ad57549b17f06d0352b3b132562f1b4..52b02aca3a427d6f648414cc0dc2caae0e8d9cca 100644
(file)
--- a/
clients/memcat.cc
+++ b/
clients/memcat.cc
@@
-1,4
+1,5
@@
/* LibMemcached
/* LibMemcached
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2006-2009 Brian Aker
* All rights reserved.
*
* Copyright (C) 2006-2009 Brian Aker
* All rights reserved.
*
@@
-9,14
+10,14
@@
*
*/
*
*/
-#include <config.h>
+#include <
mem_
config.h>
#include <cstdio>
#include <cstring>
#include <getopt.h>
#include <iostream>
#include <unistd.h>
#include <cstdio>
#include <cstring>
#include <getopt.h>
#include <iostream>
#include <unistd.h>
-#include <libmemcached/memcached.h>
+#include <libmemcached
-1.0
/memcached.h>
#include "utilities.h"
#include "utilities.h"
@@
-38,35
+39,41
@@
static char *opt_file;
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
- memcached_st *memc;
char *string;
size_t string_length;
uint32_t flags;
memcached_return_t rc;
char *string;
size_t string_length;
uint32_t flags;
memcached_return_t rc;
- memcached_server_st *servers;
- int return_code=
0
;
+ int return_code=
EXIT_SUCCESS
;
options_parse(argc, argv);
initialize_sockets();
options_parse(argc, argv);
initialize_sockets();
- if (
!opt_servers
)
+ if (
opt_servers == NULL
)
{
char *temp;
if ((temp= getenv("MEMCACHED_SERVERS")))
{
char *temp;
if ((temp= getenv("MEMCACHED_SERVERS")))
+ {
opt_servers= strdup(temp);
opt_servers= strdup(temp);
- else
+ }
+
+ if (opt_servers == NULL)
{
{
-
fprintf(stderr, "No Servers provided\n")
;
- exit(
1
);
+
std::cerr << "No servers provied" << std::endl
;
+ exit(
EXIT_FAILURE
);
}
}
}
}
- memc= memcached_create(NULL);
- process_hash_option(memc, opt_hash);
+ 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;
+ return EXIT_FAILURE;
+ }
- servers= memcached_servers_parse(opt_servers);
+ memcached_st* memc= memcached_create(NULL);
+ process_hash_option(memc, opt_hash);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
memcached_server_push(memc, servers);
memcached_server_list_free(servers);
@@
-100,69
+107,66
@@
int main(int argc, char *argv[])
if (opt_displayflag)
{
if (opt_verbose)
if (opt_displayflag)
{
if (opt_verbose)
- printf("key: %s\nflags: ", argv[optind]);
- printf("%x\n", flags);
+ {
+ std::cout << "key: " << argv[optind] << std::endl << "flags: " << flags << std::endl;
+ }
}
else
{
if (opt_verbose)
{
}
else
{
if (opt_verbose)
{
- printf("key: %s\nflags: %x\nlength: %lu\nvalue: ",
- argv[optind], flags, (unsigned long)string_length);
+ std::cout << "key: " << argv[optind] << std::endl << "flags: " << flags << "length: " << string_length << std::endl << "value: ";
}
if (opt_file)
{
}
if (opt_file)
{
- FILE *fp;
- size_t written;
-
- fp= fopen(opt_file, "w");
- if (!fp)
+ FILE *fp= fopen(opt_file, "w");
+ if (fp == NULL)
{
perror("fopen");
{
perror("fopen");
- return_code=
-1
;
+ return_code=
EXIT_FAILURE
;
break;
}
break;
}
- written= fwrite(string, 1, string_length, fp);
+
size_t
written= fwrite(string, 1, string_length, fp);
if (written != string_length)
{
if (written != string_length)
{
-
fprintf(stderr, "error writing file (written %lu, should be %lu)\n", (unsigned long)written, (unsigned long)string_length)
;
- return_code=
-1
;
+
std::cerr << "error writing file to file " << opt_file << " wrote " << written << ", should have written" << string_length << std::endl
;
+ return_code=
EXIT_FAILURE
;
break;
}
if (fclose(fp))
{
break;
}
if (fclose(fp))
{
-
fprintf(stderr, "error closing file\n")
;
- return_code=
-1
;
+
std::cerr << "error closing " << opt_file << std::endl
;
+ return_code=
EXIT_FAILURE
;
break;
}
}
else
{
break;
}
}
else
{
- printf("%.*s\n", (int)string_length, string);
+ std::cout.write(string, string_length);
+ std::cout << std::endl;
}
free(string);
}
}
else if (rc != MEMCACHED_NOTFOUND)
{
}
free(string);
}
}
else if (rc != MEMCACHED_NOTFOUND)
{
- fprintf(stderr, "memcat: %s: memcache error %s",
- argv[optind], memcached_strerror(memc, rc));
+ std::cerr << "error on " << argv[optind] << "(" << memcached_strerror(memc, rc) << ")";
if (memcached_last_error_errno(memc))
{
if (memcached_last_error_errno(memc))
{
-
fprintf(stderr, " system error %s", strerror(memcached_last_error_errno(memc)))
;
+
std::cerr << " system error (" << strerror(memcached_last_error_errno(memc)) << ")" << std::endl
;
}
}
-
fprintf(stderr, "\n")
;
+
std::cerr << std::endl
;
- return_code=
-1
;
+ return_code=
EXIT_FAILURE
;
break;
}
else // Unknown Issue
{
break;
}
else // Unknown Issue
{
-
fprintf(stderr, "memcat: %s not found\n", argv[optind])
;
- return_code=
-1
;
+
std::cerr << "error on " << argv[optind] << "("<< memcached_strerror(NULL, rc) << ")" << std::endl
;
+ return_code=
EXIT_FAILURE
;
}
optind++;
}
}
optind++;
}
@@
-170,9
+174,13
@@
int main(int argc, char *argv[])
memcached_free(memc);
if (opt_servers)
memcached_free(memc);
if (opt_servers)
+ {
free(opt_servers);
free(opt_servers);
+ }
if (opt_hash)
if (opt_hash)
+ {
free(opt_hash);
free(opt_hash);
+ }
return return_code;
}
return return_code;
}
@@
-181,7
+189,6
@@
int main(int argc, char *argv[])
void options_parse(int argc, char *argv[])
{
int option_index= 0;
void options_parse(int argc, char *argv[])
{
int option_index= 0;
- int option_rv;
memcached_programs_help_st help_options[]=
{
memcached_programs_help_st help_options[]=
{
@@
-207,7
+214,7
@@
void options_parse(int argc, char *argv[])
while (1)
{
while (1)
{
- option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+
int
option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
if (option_rv == -1) break;
switch (option_rv)
{
if (option_rv == -1) break;
switch (option_rv)
{
@@
-250,7
+257,7
@@
void options_parse(int argc, char *argv[])
case '?':
/* getopt_long already printed an error message. */
case '?':
/* getopt_long already printed an error message. */
- exit(
1
);
+ exit(
EXIT_FAILURE
);
default:
abort();
}
default:
abort();
}