-INCLUDES = -I$(top_builddir)/include\r
+INCLUDES = -I$(top_builddir)/include -Wall\r
LIBS =\r
\r
lib_LTLIBRARIES = libmemcached.la\r
void memcached_deinit(memcached_st *ptr)
{
unsigned int x;
- memcached_host_st *host_ptr;
if (ptr->hosts)
{
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%s %.*s %u\r\n", verb,
- key_length, key,
+ (int)key_length, key,
offset);
if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
- {
- fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
-
return MEMCACHED_WRITE_FAILURE;
- }
memset(buffer, 0, MEMCACHED_DEFAULT_COMMAND_SIZE);
send_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
unsigned int x;
struct sockaddr_in localAddr, servAddr;
struct hostent *h;
- memcached_host_st *host_ptr;
if (ptr->connected)
return MEMCACHED_SUCCESS;
for (x= 0; x < ptr->number_of_hosts; x++)
{
if ((h= gethostbyname(ptr->hosts[x].hostname)) == NULL)
- {
- fprintf(stderr, "unknown host '%s'\n", ptr->hosts[x].hostname);
return MEMCACHED_HOST_LOCKUP_FAILURE;
- }
servAddr.sin_family= h->h_addrtype;
memcpy((char *) &servAddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length);
/* Create the socket */
if ((ptr->hosts[0].fd= socket(AF_INET, SOCK_STREAM, 0)) < 0)
- {
- fprintf(stderr, "cannot open socket");
return MEMCACHED_CONNECTION_SOCKET_CREATE_FAILURE;
- }
/* bind any port number */
localAddr.sin_port = htons(0);
if (bind(ptr->hosts[0].fd, (struct sockaddr *) &localAddr, sizeof(localAddr)) < 0)
- {
- fprintf(stderr, "cannot bind port TCP %u\n", ptr->hosts[x].port);
return(MEMCACHED_CONNECTION_BIND_FAILURE);
- }
/* connect to server */
if (connect(ptr->hosts[0].fd, (struct sockaddr *) &servAddr, sizeof(servAddr)) < 0)
- {
- fprintf(stderr, "cannot connect to host '%s' (%u) (error: %s)\n", ptr->hosts[x].hostname,
- ptr->hosts[x].port,
- strerror(errno));
return MEMCACHED_HOST_LOCKUP_FAILURE;
- }
}
ptr->connected= 1;
if (expiration)
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s %u\r\n", key_length, key, expiration);
+ "delete %.*s %llu\r\n", (int)key_length, key,
+ (unsigned long long)expiration);
else
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "delete %.*s\r\n", key_length, key);
- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
- {
- fprintf(stderr, "failed set on %.*s TCP\n", key_length+1, key);
+ "delete %.*s\r\n", (int)key_length, key);
+ if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
return MEMCACHED_WRITE_FAILURE;
- }
return memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, server_key);
}
{
if (expiration)
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "flush_all %u\r\n", expiration);
+ "flush_all %llu\r\n", (unsigned long long)expiration);
else
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"flush_all\r\n");
if ((write(ptr->hosts[x].fd, buffer, send_length) == -1))
- {
- fprintf(stderr, "failed flush_all TCP\n");
-
return MEMCACHED_WRITE_FAILURE;
- }
rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, "get %.*s\r\n",
- key_length, key);
+ (int)key_length, key);
if (*error != MEMCACHED_SUCCESS)
return NULL;
if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
{
- fprintf(stderr, "failed fetch on %.*s TCP\n", key_length+1, key);
*error= MEMCACHED_WRITE_FAILURE;
return NULL;
}
memcached_return memcached_stat_hostname(memcached_stat_st *stat, char *args,
char *hostname, unsigned int port)
{
- size_t send_length;
memcached_return rc;
- char buffer[HUGE_STRING_LEN];
memcached_st memc;
memcached_init(&memc);
server_key= memcached_generate_hash(key, key_length) % ptr->number_of_hosts;
write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
- "%s %.*s %u %u %u\r\n", verb,
- key_length, key, flags, expiration, value_length);
+ "%s %.*s %x %llu %zu\r\n", verb,
+ (int)key_length, key, flags,
+ (unsigned long long)expiration, value_length);
if ((sent_length= write(ptr->hosts[server_key].fd, buffer, write_length)) == -1)
- {
- fprintf(stderr, "failed %s on %.*s: %s\n", verb, key_length+1, key, strerror(errno));
-
return MEMCACHED_WRITE_FAILURE;
- }
assert(write_length == sent_length);
- WATCHPOINT;
- printf("About to push %.*s\n", value_length, value);
- WATCHPOINT;
if ((sent_length= write(ptr->hosts[server_key].fd, value, value_length)) == -1)
- {
- fprintf(stderr, "failed %s on %.*s: %s\n", verb, key_length+1, key, strerror(errno));
-
return MEMCACHED_WRITE_FAILURE;
- }
assert(value_length == sent_length);
- if ((sent_length= write(ptr->hosts[server_key].fd, "\r\n", 2)) == -1)
- {
- fprintf(stderr, "failed %s on %.*s: %s\n", verb, key_length+1, key, strerror(errno));
+ if ((sent_length= write(ptr->hosts[server_key].fd, "\r\n", 2)) == -1)
return MEMCACHED_WRITE_FAILURE;
- }
assert(2 == sent_length);
sent_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
case MEMCACHED_PARTIAL_READ:
return "PARTIAL READ";
case MEMCACHED_SOME_ERRORS:
- return "SOME ERRORS WERE REPORTED ";
+ return "SOME ERRORS WERE REPORTED";
};
+
+ return "COMPLETELY UNKNOWN ERROR, SOMEONE FORGOT TO UPDATE ERROR MESSAGES";
}
memcached_return rc;
if ((write(ptr->hosts[x].fd, buffer, send_length) == -1))
- {
- fprintf(stderr, "failed verbosity\n");
-
return MEMCACHED_WRITE_FAILURE;
- }
rc= memcached_response(ptr, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, x);
-INCLUDES = -I$(top_builddir)/include\r
+INCLUDES = -I$(top_builddir)/include -Wall\r
LDADDS = ../lib/libmemcached.la\r
\r
bin_PROGRAMS = memcat memcp memstat memrm\r
/* Prototypes */\r
void options_parse(int argc, char *argv[]);\r
\r
-static int opt_verbose;\r
-static int opt_displayflag;\r
+static int opt_verbose= 0;\r
+static int opt_displayflag= 0;\r
static char *opt_servers;\r
\r
int main(int argc, char *argv[])\r
memcached_st *memc;\r
char *string;\r
size_t string_length;\r
- uint16_t flags;\r
+ uint16_t flags;\r
memcached_return rc;\r
\r
memc= memcached_init(NULL);\r
{\r
if (opt_displayflag)\r
{\r
- if (opt_verbose)\r
- printf("key: %s\nflags: ", argv[optind]);\r
- printf("%u\n", flags);\r
+ if (opt_verbose)\r
+ printf("key: %s\nflags: ", argv[optind]);\r
+ printf("%x\n", flags);\r
}\r
else \r
{\r
- if (opt_verbose)\r
- printf("key: %s\nflags: %u\nlength: %uz\nvalue: ",\r
- argv[optind], flags, string_length);\r
- printf("%.*s\n", string_length, string);\r
+ if (opt_verbose)\r
+ printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",\r
+ argv[optind], flags, string_length);\r
+ printf("%.*s\n", (int)string_length, string);\r
free(string);\r
}\r
}\r
else\r
{\r
fprintf(stderr, "memcat: %s: memcache error %s\n", \r
- argv[optind], memcached_strerror(memc, rc));\r
+ argv[optind], memcached_strerror(memc, rc));\r
}\r
optind++;\r
}\r
\r
memcached_deinit(memc);\r
\r
+ free(opt_servers);\r
+\r
return 0;\r
};\r
\r
\r
void options_parse(int argc, char *argv[])\r
{\r
- int option_index = 0;\r
+ int option_index= 0;\r
int option_rv;\r
\r
- static struct option long_options[] =\r
+ static struct option long_options[]=\r
{\r
{"version", no_argument, NULL, OPT_VERSION},\r
{"help", no_argument, NULL, OPT_HELP},\r
\r
while (1) \r
{\r
- option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index);\r
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);\r
if (option_rv == -1) break;\r
- switch (option_rv) {\r
+ switch (option_rv)\r
+ {\r
case 0:\r
break;\r
case OPT_VERSION: /* --version or -V */\r
exit(0);\r
break;\r
case OPT_SERVERS: /* --servers or -s */\r
- opt_servers= optarg;\r
+ opt_servers= strdup(optarg);\r
break;\r
case '?':\r
/* getopt_long already printed an error message. */\r
\r
#include <memcached.h>\r
#include "client_options.h"\r
+#include "utilities.h"\r
\r
/* Prototypes */\r
void options_parse(int argc, char *argv[]);\r
\r
static int opt_verbose= 0;\r
static char *opt_servers= NULL;\r
-static int opt_method= 0;\r
-uint16_t opt_flags= 0;\r
-time_t opt_expires= 0;\r
+static int opt_method= OPT_SET;\r
+static uint16_t opt_flags= 0;\r
+static time_t opt_expires= 0;\r
\r
int main(int argc, char *argv[])\r
{\r
memcached_st *memc;\r
- char *string;\r
- size_t string_length;\r
memcached_return rc;\r
+\r
options_parse(argc, argv);\r
\r
memc= memcached_init(NULL);\r
+\r
if (opt_servers)\r
parse_opt_servers(memc, opt_servers);\r
else\r
char *file_buffer_ptr;\r
\r
fd= open(argv[optind], O_RDONLY);\r
- if (fd < 0) \r
+ if (fd < 0)\r
{\r
fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno));\r
optind++;\r
{\r
static char *opstr[] = { "set", "add", "replace" };\r
printf("op: %s\nsource file: %s\nlength: %zu\n"\r
- "key: %s\nflags: %u\n expires: %llu\n",\r
- opstr[opt_method], argv[optind], sbuf.st_size,\r
- ptr, opt_flags, opt_expires);\r
+ "key: %s\nflags: %x\n expires: %llu\n",\r
+ opstr[opt_method], argv[optind], (size_t)sbuf.st_size,\r
+ ptr, opt_flags, (unsigned long long)opt_expires);\r
}\r
\r
if ((file_buffer_ptr= (char *)malloc(sizeof(char) * sbuf.st_size)) == NULL)\r
\r
memcached_deinit(memc);\r
\r
- cleanup();\r
+ free(opt_servers);\r
\r
return 0;\r
-};\r
+}\r
\r
void options_parse(int argc, char *argv[])\r
{\r
int option_index= 0;\r
int option_rv;\r
\r
- static struct option long_options[] =\r
+ static struct option long_options[]=\r
{\r
{"version", no_argument, NULL, OPT_VERSION},\r
{"help", no_argument, NULL, OPT_HELP},\r
\r
if (option_rv == -1) break;\r
\r
- switch (option_rv) {\r
+ switch (option_rv)\r
+ {\r
case 0:\r
break;\r
case OPT_VERSION: /* --version or -V */\r
printf("useful help messages go here\n");\r
exit(0);\r
case OPT_SERVERS: /* --servers or -s */\r
- opt_servers= strdup_cleanup(optarg);\r
+ opt_servers= strdup(optarg);\r
break;\r
case OPT_FLAG: /* --flag */\r
- opt_flags= (uint16_t)strtol(optarg, (char **)NULL, 10);\r
+ opt_flags= (uint16_t)strtol(optarg, (char **)NULL, 16);\r
break;\r
case OPT_EXPIRE: /* --expire */\r
- opt_expires= (time_t)strtol(optarg, (char **)NULL, 10);\r
+ opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10);\r
break;\r
case OPT_SET:\r
opt_method= OPT_SET;\r
#include <getopt.h>\r
#include <memcached.h>\r
#include "client_options.h"\r
+#include "utilities.h"\r
\r
-static int opt_verbose;\r
-static char *opt_servers;\r
+static int opt_verbose= 0;\r
+static time_t opt_expire= 0;\r
+static char *opt_servers= NULL;\r
+\r
+/* Prototypes */\r
+void options_parse(int argc, char *argv[]);\r
\r
int main(int argc, char *argv[])\r
{\r
memcached_st *memc;\r
- char *string;\r
- size_t string_length;\r
- time_t expires = 0;\r
memcached_return rc;\r
\r
- static struct option long_options[] =\r
+ options_parse(argc, argv);\r
+\r
+ memc= memcached_init(NULL);\r
+\r
+ parse_opt_servers(memc, opt_servers);\r
+\r
+ if (opt_servers)\r
+ parse_opt_servers(memc, opt_servers);\r
+ \r
+ while (optind <= argc) \r
+ {\r
+ if (opt_verbose) \r
+ printf("key: %s\nexpires: %llu\n", argv[optind], (unsigned long long)opt_expire);\r
+ rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire);\r
+\r
+ if (rc != MEMCACHED_SUCCESS) \r
{\r
- {"version", no_argument, NULL, OPT_VERSION},\r
- {"help", no_argument, NULL, OPT_HELP},\r
- {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},\r
- {"debug", no_argument, &opt_verbose, OPT_DEBUG},\r
- {"servers", required_argument, NULL, OPT_SERVERS},\r
- {"expire", required_argument, NULL, OPT_EXPIRE},\r
- {0, 0, 0, 0},\r
- };\r
- int option_index = 0;\r
+ fprintf(stderr, "memrm: %s: memcache error %s\n", \r
+ argv[optind], memcached_strerror(memc, rc));\r
+ }\r
+\r
+ optind++;\r
+ }\r
+\r
+ memcached_deinit(memc);\r
+\r
+ free(opt_servers);\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+void options_parse(int argc, char *argv[])\r
+{\r
+ static struct option long_options[]=\r
+ {\r
+ {"version", no_argument, NULL, OPT_VERSION},\r
+ {"help", no_argument, NULL, OPT_HELP},\r
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},\r
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},\r
+ {"servers", required_argument, NULL, OPT_SERVERS},\r
+ {"expire", required_argument, NULL, OPT_EXPIRE},\r
+ {0, 0, 0, 0},\r
+ };\r
+ int option_index= 0;\r
int option_rv;\r
\r
while (1) \r
{\r
- option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index);\r
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);\r
if (option_rv == -1) break;\r
- switch (option_rv) {\r
+ switch (option_rv)\r
+ {\r
case 0:\r
break;\r
case OPT_VERSION: /* --version or -V */\r
exit(0);\r
break;\r
case OPT_SERVERS: /* --servers or -s */\r
- opt_servers = optarg;\r
+ opt_servers= strdup(optarg);\r
break;\r
case OPT_EXPIRE: /* --expire */\r
- expires = (time_t)strtol(optarg, (char **)NULL, 10);\r
+ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);\r
break;\r
case '?':\r
/* getopt_long already printed an error message. */\r
abort();\r
}\r
}\r
-\r
- memc= memcached_init(NULL);\r
- parse_opt_servers(memc, opt_servers);\r
- \r
- while (optind <= argc) \r
- {\r
- if (opt_verbose) \r
- printf("key: %s\nexpires: %llu\n", argv[optind], expires);\r
- rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), expires);\r
-\r
- if (rc != MEMCACHED_SUCCESS) \r
- {\r
- fprintf(stderr, "memrm: %s: memcache error %s\n", \r
- argv[optind], memcached_strerror(memc, rc));\r
- }\r
-\r
- optind++;\r
- }\r
-\r
- memcached_deinit(memc);\r
-\r
- return 0;\r
-};\r
+}\r
void options_parse(int argc, char *argv[])
{
- static struct option long_options[] =
+ static struct option long_options[]=
{
{"version", no_argument, NULL, OPT_VERSION},
{"help", no_argument, NULL, OPT_HELP},
{0, 0, 0, 0},
};
- int option_index = 0;
+ int option_index= 0;
int option_rv;
while (1)
{
- option_rv = getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
if (option_rv == -1) break;
- switch (option_rv) {
+ switch (option_rv)
+ {
case 0:
break;
case OPT_VERSION: /* --version or -V */
exit(0);
break;
case OPT_SERVERS: /* --servers or -s */
- opt_servers = optarg;
+ opt_servers= optarg;
break;
case '?':
/* getopt_long already printed an error message. */
#include <memcached.h>
-static char **cleanup_list= NULL;
-static char cleanup_list_length= 0;
-
void parse_opt_servers(memcached_st *memc,
char *server_strings)
{
}
}
}
-
-void cleanup(void)
-{
- unsigned int x;
- for (x= 0; x < cleanup_list_length; x++)
- free(cleanup_list[x]);
-
- free(cleanup_list);
-}
-
-char *strdup_cleanup(const char *str)
-{
- char *ptr;
-
- ptr= strdup(str);
-
- cleanup_list= (char **)realloc(cleanup_list, sizeof(char *) * (cleanup_list_length+1));
- cleanup_list[cleanup_list_length]= ptr;
- cleanup_list_length++;
-
- return ptr;
-}