Also reworked code to use send/recv over write/read.
More logic in get_test3test case
0.3
* Jeff Fisher <guppy@techmonkeys.org> provided a spec file
+ * Added support for Solaris
+ * Fixed read to be recv and write to be send
0.2 Thu Sep 27 03:46:57 PDT 2007
* First public version
-AC_INIT(src/memcat.c)\r
-AC_CONFIG_AUX_DIR(config)\r
-AM_CONFIG_HEADER(config.h)\r
-AM_INIT_AUTOMAKE("libmemcached", 0.2 )\r
-\r
-AC_PROG_CC\r
-AC_PROG_LIBTOOL\r
-LIBTOOL="$LIBTOOL --preserve-dup-deps"\r
-AC_SUBST(LIBTOOL)dnl\r
-\r
-AC_C_CONST\r
-AC_TYPE_SIZE_T\r
-AC_CHECK_HEADERS(limits.h syslimits.h)\r
-AC_OUTPUT(Makefile src/Makefile tests/Makefile docs/Makefile lib/Makefile include/Makefile support/Makefile)\r
+AC_INIT(src/memcat.c)
+AC_CONFIG_AUX_DIR(config)
+AM_CONFIG_HEADER(config.h)
+AM_INIT_AUTOMAKE("libmemcached", 0.2 )
+
+AC_PROG_CC
+AC_PROG_LIBTOOL
+LIBTOOL="$LIBTOOL --preserve-dup-deps"
+AC_SUBST(LIBTOOL)dnl
+
+# We only support GCC and Sun's forte at the moment
+if test "$GCC" = "yes"
+then
+ CFLAGS="-Wall"
+ CXXFLAGS="$CXXFLAGS -fno-implicit-templates -fno-exceptions -fno-rtti"
+else
+ CFLAGS="-Xa -xstrconst -mt -D_FORTEC_ -fast -m64"
+ LDFLAGS="-lsocket -lnsl"
+ DTRACEFLAGS="-64"
+fi
+
+AC_C_CONST
+AC_TYPE_SIZE_T
+AC_CHECK_HEADERS(limits.h syslimits.h)
+AC_OUTPUT(Makefile src/Makefile tests/Makefile docs/Makefile lib/Makefile include/Makefile support/Makefile)
-INCLUDES = -I$(top_builddir)/include -Wall\r
-LIBS =\r
-\r
-lib_LTLIBRARIES = libmemcached.la\r
-libmemcached_la_SOURCES = memcached.c \\r
- memcached_strerror.c \\r
- memcached_connect.c \\r
- memcached_response.c \\r
- memcached_get.c \\r
- memcached_storage.c \\r
- memcached_delete.c \\r
- memcached_hash.c \\r
- memcached_auto.c \\r
- memcached_verbosity.c \\r
- memcached_quit.c \\r
- memcached_flush.c \\r
- memcached_string.c \\r
- memcached_stats.c\r
+INCLUDES = -I$(top_builddir)/include
+LIBS =
+
+lib_LTLIBRARIES = libmemcached.la
+libmemcached_la_SOURCES = memcached.c \
+ memcached_strerror.c \
+ memcached_connect.c \
+ memcached_response.c \
+ memcached_get.c \
+ memcached_storage.c \
+ memcached_delete.c \
+ memcached_hash.c \
+ memcached_auto.c \
+ memcached_verbosity.c \
+ memcached_quit.c \
+ memcached_flush.c \
+ memcached_string.c \
+ memcached_stats.c
offset);
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= write(ptr->hosts[server_key].fd, buffer, send_length);
+ sent_length= send(ptr->hosts[server_key].fd, buffer, send_length, 0);
if (sent_length == -1 || sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= write(ptr->hosts[server_key].fd, buffer, send_length);
+ sent_length= send(ptr->hosts[server_key].fd, buffer, send_length, 0);
if (sent_length == -1 || sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= write(ptr->hosts[x].fd, buffer, send_length);
+ sent_length= send(ptr->hosts[x].fd, buffer, send_length, 0);
if (sent_length == -1 || sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
string_ptr++;
if (end_ptr == string_ptr)
goto read_error;
-
for (next_ptr= string_ptr; end_ptr == string_ptr || *string_ptr != ' '; string_ptr++);
*flags= (uint16_t)strtol(next_ptr, &string_ptr, 10);
if (*value_length)
{
size_t read_length;
+ size_t partial_length;
+ size_t to_read;
char *value;
+ char *value_ptr;
/* We add two bytes so that we can walk the \r\n */
value= (char *)malloc(((*value_length) +2) * sizeof(char));
+ memset(value, 0, ((*value_length) +2) * sizeof(char));
if (!value)
{
return NULL;
}
- read_length= read(ptr->hosts[server_key].fd, value, (*value_length)+2);
+ value_ptr= value;
+ read_length= 0;
+ to_read= (*value_length) + 2;
+ /* This is overkill */
+ while ((partial_length= recv(ptr->hosts[server_key].fd, value_ptr, to_read, 0)) > 0)
+ {
+ value_ptr+= partial_length;
+ read_length+= partial_length;
+ to_read-= partial_length;
+ if (read_length == (size_t)(*value_length + 2))
+ break;
+ }
if (read_length != (size_t)(*value_length + 2))
{
if (*error != MEMCACHED_SUCCESS)
return NULL;
- if ((write(ptr->hosts[server_key].fd, buffer, send_length) == -1))
+ if ((send(ptr->hosts[server_key].fd, buffer, send_length, 0) == -1))
{
*error= MEMCACHED_WRITE_FAILURE;
return NULL;
memcached_string_st *string= cursor_key_exec[x];
memcached_string_append(ptr, string, "\r\n", 2);
- if ((write(ptr->hosts[x].fd, string->string,
- memcached_string_length(ptr, string)) == -1))
+ if ((send(ptr->hosts[x].fd, string->string,
+ memcached_string_length(ptr, string), 0) == -1))
{
memcached_quit(ptr);
rc= MEMCACHED_SOME_ERRORS;
while (1)
{
unsigned int read_length;
- read_length= read(ptr->hosts[server_key].fd, buffer_ptr, 1);
+ read_length= recv(ptr->hosts[server_key].fd, buffer_ptr, 1, 0);
if (read_length != 1)
return MEMCACHED_UNKNOWN_READ_FAILURE;
default:
return MEMCACHED_UNKNOWN_READ_FAILURE;
- return MEMCACHED_READ_FAILURE;
}
return MEMCACHED_SUCCESS;
if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- sent_length= write(ptr->hosts[server_key].fd, buffer, send_length);
+ sent_length= send(ptr->hosts[server_key].fd, buffer, send_length, 0);
if (sent_length == -1 || sent_length != send_length)
return MEMCACHED_WRITE_FAILURE;
(unsigned long long)expiration, value_length);
if (write_length >= MEMCACHED_DEFAULT_COMMAND_SIZE)
return MEMCACHED_WRITE_FAILURE;
- if ((sent_length= write(ptr->hosts[server_key].fd, buffer, write_length)) == -1)
+ if ((sent_length= send(ptr->hosts[server_key].fd, buffer, write_length, 0)) == -1)
return MEMCACHED_WRITE_FAILURE;
assert(write_length == sent_length);
- if ((sent_length= write(ptr->hosts[server_key].fd, value, value_length)) == -1)
+ if ((sent_length= send(ptr->hosts[server_key].fd, value, value_length, 0)) == -1)
return MEMCACHED_WRITE_FAILURE;
assert(value_length == sent_length);
- if ((sent_length= write(ptr->hosts[server_key].fd, "\r\n", 2)) == -1)
+ if ((sent_length= send(ptr->hosts[server_key].fd, "\r\n", 2, 0)) == -1)
return MEMCACHED_WRITE_FAILURE;
assert(2 == sent_length);
- sent_length= read(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE);
+ sent_length= recv(ptr->hosts[server_key].fd, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, 0);
if (sent_length && buffer[0] == 'S') /* STORED */
return MEMCACHED_SUCCESS;
default:
return "Gibberish returned!";
};
-
- return "COMPLETELY UNKNOWN ERROR, SOMEONE FORGOT TO UPDATE ERROR MESSAGES";
}
{
memcached_return rc;
- if ((write(ptr->hosts[x].fd, buffer, send_length) == -1))
+ if ((send(ptr->hosts[x].fd, buffer, send_length, 0) == -1))
{
continue;
return MEMCACHED_SOME_ERRORS;
-INCLUDES = -I$(top_builddir)/include -Wall\r
-LDADDS = ../lib/libmemcached.la\r
-\r
-bin_PROGRAMS = memcat memcp memstat memrm memflush\r
-\r
-noinst_HEADERS = client_options.h utilities.h\r
-\r
-memcat_SOURCES = memcat.c utilities.c\r
-memcat_LDADD = $(LDADDS)\r
-\r
-memcp_SOURCES = memcp.c utilities.c\r
-memcp_LDADD = $(LDADDS)\r
-\r
-memstat_SOURCES = memstat.c utilities.c\r
-memstat_LDADD = $(LDADDS)\r
-\r
-memrm_SOURCES = memrm.c utilities.c\r
-memrm_LDADD = $(LDADDS)\r
-\r
-memflush_SOURCES = memflush.c utilities.c\r
-memflush_LDADD = $(LDADDS)\r
+INCLUDES = -I$(top_builddir)/include
+LDADDS = ../lib/libmemcached.la
+
+bin_PROGRAMS = memcat memcp memstat memrm memflush
+
+noinst_HEADERS = client_options.h utilities.h
+
+memcat_SOURCES = memcat.c utilities.c
+memcat_LDADD = $(LDADDS)
+
+memcp_SOURCES = memcp.c utilities.c
+memcp_LDADD = $(LDADDS)
+
+memstat_SOURCES = memstat.c utilities.c
+memstat_LDADD = $(LDADDS)
+
+memrm_SOURCES = memrm.c utilities.c
+memrm_LDADD = $(LDADDS)
+
+memflush_SOURCES = memflush.c utilities.c
+memflush_LDADD = $(LDADDS)
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <getopt.h>\r
-#include <memcached.h>\r
-\r
-#include "client_options.h"\r
-#include "utilities.h"\r
-\r
-\r
-/* Prototypes */\r
-void options_parse(int argc, char *argv[]);\r
-\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
-{\r
- memcached_st *memc;\r
- char *string;\r
- size_t string_length;\r
- uint16_t flags;\r
- memcached_return rc;\r
-\r
- memc= memcached_init(NULL);\r
-\r
- options_parse(argc, argv);\r
-\r
- if (opt_servers)\r
- parse_opt_servers(memc, opt_servers);\r
-\r
- while (optind < argc) \r
- {\r
- string= memcached_get(memc, argv[optind], strlen(argv[optind]),\r
- &string_length, &flags, &rc);\r
- if (rc == MEMCACHED_SUCCESS) \r
- {\r
- if (opt_displayflag)\r
- {\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: %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
- }\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_rv;\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
- {"flag", no_argument, &opt_displayflag, OPT_FLAG},\r
- {0, 0, 0, 0},\r
- };\r
-\r
- while (1) \r
- {\r
- option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);\r
- if (option_rv == -1) break;\r
- switch (option_rv)\r
- {\r
- case 0:\r
- break;\r
- case OPT_VERBOSE: /* --verbose or -v */\r
- opt_verbose = OPT_VERBOSE;\r
- break;\r
- case OPT_DEBUG: /* --debug or -d */\r
- opt_verbose = OPT_DEBUG;\r
- break;\r
- case OPT_VERSION: /* --version or -V */\r
- printf("memcache tools, memcat, v1.0\n");\r
- exit(0);\r
- break;\r
- case OPT_HELP: /* --help or -h */\r
- printf("useful help messages go here\n");\r
- exit(0);\r
- break;\r
- case OPT_SERVERS: /* --servers or -s */\r
- opt_servers= strdup(optarg);\r
- break;\r
- case '?':\r
- /* getopt_long already printed an error message. */\r
- exit(1);\r
- default:\r
- abort();\r
- }\r
- }\r
-}\r
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <memcached.h>
+
+#include "client_options.h"
+#include "utilities.h"
+
+
+/* Prototypes */
+void options_parse(int argc, char *argv[]);
+
+static int opt_verbose= 0;
+static int opt_displayflag= 0;
+static char *opt_servers;
+
+int main(int argc, char *argv[])
+{
+ memcached_st *memc;
+ char *string;
+ size_t string_length;
+ uint16_t flags;
+ memcached_return rc;
+
+ memc= memcached_init(NULL);
+
+ options_parse(argc, argv);
+
+ if (opt_servers)
+ parse_opt_servers(memc, opt_servers);
+
+ while (optind < argc)
+ {
+ string= memcached_get(memc, argv[optind], strlen(argv[optind]),
+ &string_length, &flags, &rc);
+ if (rc == MEMCACHED_SUCCESS)
+ {
+ if (opt_displayflag)
+ {
+ if (opt_verbose)
+ printf("key: %s\nflags: ", argv[optind]);
+ printf("%x\n", flags);
+ }
+ else
+ {
+ if (opt_verbose)
+ printf("key: %s\nflags: %x\nlength: %zu\nvalue: ",
+ argv[optind], flags, string_length);
+ printf("%.*s\n", (int)string_length, string);
+ free(string);
+ }
+ }
+ else
+ {
+ fprintf(stderr, "memcat: %s: memcache error %s\n",
+ argv[optind], memcached_strerror(memc, rc));
+ }
+ optind++;
+ }
+
+ memcached_deinit(memc);
+
+ free(opt_servers);
+
+ return 0;
+};
+
+
+void options_parse(int argc, char *argv[])
+{
+ int option_index= 0;
+ int option_rv;
+
+ static struct option long_options[]=
+ {
+ {"version", no_argument, NULL, OPT_VERSION},
+ {"help", no_argument, NULL, OPT_HELP},
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},
+ {"servers", required_argument, NULL, OPT_SERVERS},
+ {"flag", no_argument, &opt_displayflag, OPT_FLAG},
+ {0, 0, 0, 0},
+ };
+
+ while (1)
+ {
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+ if (option_rv == -1) break;
+ switch (option_rv)
+ {
+ case 0:
+ break;
+ case OPT_VERBOSE: /* --verbose or -v */
+ opt_verbose = OPT_VERBOSE;
+ break;
+ case OPT_DEBUG: /* --debug or -d */
+ opt_verbose = OPT_DEBUG;
+ break;
+ case OPT_VERSION: /* --version or -V */
+ printf("memcache tools, memcat, v1.0\n");
+ exit(0);
+ break;
+ case OPT_HELP: /* --help or -h */
+ printf("useful help messages go here\n");
+ exit(0);
+ break;
+ case OPT_SERVERS: /* --servers or -s */
+ opt_servers= strdup(optarg);
+ break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ exit(1);
+ default:
+ abort();
+ }
+ }
+}
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <getopt.h>\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
-#include <fcntl.h>\r
-#include <errno.h>\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= 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
- 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
- parse_opt_servers(memc, argv[--argc]);\r
-\r
- while (optind < argc) \r
- {\r
- struct stat sbuf;\r
- int fd;\r
- char *ptr;\r
- ssize_t read_length;\r
- char *file_buffer_ptr;\r
-\r
- fd= open(argv[optind], O_RDONLY);\r
- if (fd < 0)\r
- {\r
- fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno));\r
- optind++;\r
- continue;\r
- }\r
-\r
- (void)fstat(fd, &sbuf);\r
-\r
- ptr= rindex(argv[optind], '/');\r
- if (ptr)\r
- ptr++;\r
- else\r
- ptr= argv[optind];\r
-\r
- if (opt_verbose) \r
- {\r
- static char *opstr[] = { "set", "add", "replace" };\r
- printf("op: %s\nsource file: %s\nlength: %zu\n"\r
- "key: %s\nflags: %x\nexpires: %llu\n",\r
- opstr[opt_method - OPT_SET], 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
- fprintf(stderr, "malloc: %s\n", strerror(errno)); \r
- exit(1);\r
- }\r
-\r
- if ((read_length= read(fd, file_buffer_ptr, sbuf.st_size)) == -1)\r
- {\r
- fprintf(stderr, "read: %s\n", strerror(errno)); \r
- exit(1);\r
- }\r
- assert(read_length == sbuf.st_size);\r
-\r
- if (opt_method == OPT_ADD)\r
- rc= memcached_add(memc, ptr, strlen(ptr),\r
- file_buffer_ptr, sbuf.st_size,\r
- opt_expires, opt_flags);\r
- else if (opt_method == OPT_REPLACE)\r
- rc= memcached_replace(memc, ptr, strlen(ptr),\r
- file_buffer_ptr, sbuf.st_size,\r
- opt_expires, opt_flags);\r
- else\r
- rc= memcached_set(memc, ptr, strlen(ptr),\r
- file_buffer_ptr, sbuf.st_size,\r
- opt_expires, opt_flags);\r
-\r
- if (rc != MEMCACHED_SUCCESS)\r
- fprintf(stderr, "memcp: %s: memcache error %s\n", \r
- ptr, memcached_strerror(memc, rc));\r
-\r
- free(file_buffer_ptr);\r
- close(fd);\r
- optind++;\r
- }\r
-\r
- memcached_deinit(memc);\r
-\r
- free(opt_servers);\r
-\r
- return 0;\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
- {\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
- {"flag", required_argument, NULL, OPT_FLAG},\r
- {"expire", required_argument, NULL, OPT_EXPIRE},\r
- {"set", no_argument, NULL, OPT_SET},\r
- {"add", no_argument, NULL, OPT_ADD},\r
- {"replace", no_argument, NULL, OPT_REPLACE},\r
- {0, 0, 0, 0},\r
- };\r
-\r
- while (1) \r
- {\r
- option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);\r
-\r
- if (option_rv == -1) break;\r
-\r
- switch (option_rv)\r
- {\r
- case 0:\r
- break;\r
- case OPT_VERBOSE: /* --verbose or -v */\r
- opt_verbose = OPT_VERBOSE;\r
- break;\r
- case OPT_DEBUG: /* --debug or -d */\r
- opt_verbose = OPT_DEBUG;\r
- break;\r
- case OPT_VERSION: /* --version or -V */\r
- printf("memcache tools, memcp, v1.0\n");\r
- exit(0);\r
- case OPT_HELP: /* --help or -h */\r
- printf("useful help messages go here\n");\r
- exit(0);\r
- case OPT_SERVERS: /* --servers or -s */\r
- opt_servers= strdup(optarg);\r
- break;\r
- case OPT_FLAG: /* --flag */\r
- opt_flags= (uint16_t)strtol(optarg, (char **)NULL, 16);\r
- break;\r
- case OPT_EXPIRE: /* --expire */\r
- opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10);\r
- break;\r
- case OPT_SET:\r
- opt_method= OPT_SET;\r
- break;\r
- case OPT_REPLACE:\r
- opt_method= OPT_REPLACE;\r
- break;\r
- case OPT_ADD:\r
- opt_method= OPT_ADD;\r
- break;\r
- case '?':\r
- /* getopt_long already printed an error message. */\r
- exit(1);\r
- default:\r
- abort();\r
- }\r
- }\r
-}\r
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <strings.h>
+
+#include <memcached.h>
+#include "client_options.h"
+#include "utilities.h"
+
+/* Prototypes */
+void options_parse(int argc, char *argv[]);
+
+static int opt_verbose= 0;
+static char *opt_servers= NULL;
+static int opt_method= OPT_SET;
+static uint16_t opt_flags= 0;
+static time_t opt_expires= 0;
+
+int main(int argc, char *argv[])
+{
+ memcached_st *memc;
+ memcached_return rc;
+
+ options_parse(argc, argv);
+
+ memc= memcached_init(NULL);
+
+ if (opt_servers)
+ parse_opt_servers(memc, opt_servers);
+ else
+ parse_opt_servers(memc, argv[--argc]);
+
+ while (optind < argc)
+ {
+ struct stat sbuf;
+ int fd;
+ char *ptr;
+ ssize_t read_length;
+ char *file_buffer_ptr;
+
+ fd= open(argv[optind], O_RDONLY);
+ if (fd < 0)
+ {
+ fprintf(stderr, "memcp: %s: %s\n", argv[optind], strerror(errno));
+ optind++;
+ continue;
+ }
+
+ (void)fstat(fd, &sbuf);
+
+ ptr= rindex(argv[optind], '/');
+ if (ptr)
+ ptr++;
+ else
+ ptr= argv[optind];
+
+ if (opt_verbose)
+ {
+ static char *opstr[] = { "set", "add", "replace" };
+ printf("op: %s\nsource file: %s\nlength: %zu\n"
+ "key: %s\nflags: %x\nexpires: %llu\n",
+ opstr[opt_method - OPT_SET], argv[optind], (size_t)sbuf.st_size,
+ ptr, opt_flags, (unsigned long long)opt_expires);
+ }
+
+ if ((file_buffer_ptr= (char *)malloc(sizeof(char) * sbuf.st_size)) == NULL)
+ {
+ fprintf(stderr, "malloc: %s\n", strerror(errno));
+ exit(1);
+ }
+
+ if ((read_length= read(fd, file_buffer_ptr, sbuf.st_size)) == -1)
+ {
+ fprintf(stderr, "read: %s\n", strerror(errno));
+ exit(1);
+ }
+ assert(read_length == sbuf.st_size);
+
+ if (opt_method == OPT_ADD)
+ rc= memcached_add(memc, ptr, strlen(ptr),
+ file_buffer_ptr, sbuf.st_size,
+ opt_expires, opt_flags);
+ else if (opt_method == OPT_REPLACE)
+ rc= memcached_replace(memc, ptr, strlen(ptr),
+ file_buffer_ptr, sbuf.st_size,
+ opt_expires, opt_flags);
+ else
+ rc= memcached_set(memc, ptr, strlen(ptr),
+ file_buffer_ptr, sbuf.st_size,
+ opt_expires, opt_flags);
+
+ if (rc != MEMCACHED_SUCCESS)
+ fprintf(stderr, "memcp: %s: memcache error %s\n",
+ ptr, memcached_strerror(memc, rc));
+
+ free(file_buffer_ptr);
+ close(fd);
+ optind++;
+ }
+
+ memcached_deinit(memc);
+
+ free(opt_servers);
+
+ return 0;
+}
+
+void options_parse(int argc, char *argv[])
+{
+ int option_index= 0;
+ int option_rv;
+
+ static struct option long_options[]=
+ {
+ {"version", no_argument, NULL, OPT_VERSION},
+ {"help", no_argument, NULL, OPT_HELP},
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},
+ {"servers", required_argument, NULL, OPT_SERVERS},
+ {"flag", required_argument, NULL, OPT_FLAG},
+ {"expire", required_argument, NULL, OPT_EXPIRE},
+ {"set", no_argument, NULL, OPT_SET},
+ {"add", no_argument, NULL, OPT_ADD},
+ {"replace", no_argument, NULL, OPT_REPLACE},
+ {0, 0, 0, 0},
+ };
+
+ while (1)
+ {
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+
+ if (option_rv == -1) break;
+
+ switch (option_rv)
+ {
+ case 0:
+ break;
+ case OPT_VERBOSE: /* --verbose or -v */
+ opt_verbose = OPT_VERBOSE;
+ break;
+ case OPT_DEBUG: /* --debug or -d */
+ opt_verbose = OPT_DEBUG;
+ break;
+ case OPT_VERSION: /* --version or -V */
+ printf("memcache tools, memcp, v1.0\n");
+ exit(0);
+ case OPT_HELP: /* --help or -h */
+ printf("useful help messages go here\n");
+ exit(0);
+ case OPT_SERVERS: /* --servers or -s */
+ opt_servers= strdup(optarg);
+ break;
+ case OPT_FLAG: /* --flag */
+ opt_flags= (uint16_t)strtol(optarg, (char **)NULL, 16);
+ break;
+ case OPT_EXPIRE: /* --expire */
+ opt_expires= (time_t)strtoll(optarg, (char **)NULL, 10);
+ break;
+ case OPT_SET:
+ opt_method= OPT_SET;
+ break;
+ case OPT_REPLACE:
+ opt_method= OPT_REPLACE;
+ break;
+ case OPT_ADD:
+ opt_method= OPT_ADD;
+ break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ exit(1);
+ default:
+ abort();
+ }
+ }
+}
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <getopt.h>\r
-#include <memcached.h>\r
-#include "client_options.h"\r
-#include "utilities.h"\r
-\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
- 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
- \r
- rc = memcached_flush(memc, opt_expire);\r
- if (rc != MEMCACHED_SUCCESS) \r
- {\r
- fprintf(stderr, "memflush: memcache error %s\n", \r
- memcached_strerror(memc, rc));\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
- if (option_rv == -1) break;\r
- switch (option_rv)\r
- {\r
- case 0:\r
- break;\r
- case OPT_VERBOSE: /* --verbose or -v */\r
- opt_verbose = OPT_VERBOSE;\r
- break;\r
- case OPT_DEBUG: /* --debug or -d */\r
- opt_verbose = OPT_DEBUG;\r
- break;\r
- case OPT_VERSION: /* --version or -V */\r
- printf("memcache tools, memflush, v1.0\n");\r
- exit(0);\r
- break;\r
- case OPT_HELP: /* --help or -h */\r
- printf("useful help messages go here\n");\r
- exit(0);\r
- break;\r
- case OPT_SERVERS: /* --servers or -s */\r
- opt_servers= strdup(optarg);\r
- break;\r
- case OPT_EXPIRE: /* --expire */\r
- opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);\r
- break;\r
- case '?':\r
- /* getopt_long already printed an error message. */\r
- exit(1);\r
- default:\r
- abort();\r
- }\r
- }\r
-}\r
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <memcached.h>
+#include "client_options.h"
+#include "utilities.h"
+
+static int opt_verbose= 0;
+static time_t opt_expire= 0;
+static char *opt_servers= NULL;
+
+/* Prototypes */
+void options_parse(int argc, char *argv[]);
+
+int main(int argc, char *argv[])
+{
+ memcached_st *memc;
+ memcached_return rc;
+
+ options_parse(argc, argv);
+
+ memc= memcached_init(NULL);
+
+ if (opt_servers)
+ parse_opt_servers(memc, opt_servers);
+
+ rc = memcached_flush(memc, opt_expire);
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ fprintf(stderr, "memflush: memcache error %s\n",
+ memcached_strerror(memc, rc));
+ }
+
+ memcached_deinit(memc);
+
+ free(opt_servers);
+
+ return 0;
+}
+
+
+void options_parse(int argc, char *argv[])
+{
+ static struct option long_options[]=
+ {
+ {"version", no_argument, NULL, OPT_VERSION},
+ {"help", no_argument, NULL, OPT_HELP},
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},
+ {"servers", required_argument, NULL, OPT_SERVERS},
+ {"expire", required_argument, NULL, OPT_EXPIRE},
+ {0, 0, 0, 0},
+ };
+ int option_index= 0;
+ int option_rv;
+
+ while (1)
+ {
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+ if (option_rv == -1) break;
+ switch (option_rv)
+ {
+ case 0:
+ break;
+ case OPT_VERBOSE: /* --verbose or -v */
+ opt_verbose = OPT_VERBOSE;
+ break;
+ case OPT_DEBUG: /* --debug or -d */
+ opt_verbose = OPT_DEBUG;
+ break;
+ case OPT_VERSION: /* --version or -V */
+ printf("memcache tools, memflush, v1.0\n");
+ exit(0);
+ break;
+ case OPT_HELP: /* --help or -h */
+ printf("useful help messages go here\n");
+ exit(0);
+ break;
+ case OPT_SERVERS: /* --servers or -s */
+ opt_servers= strdup(optarg);
+ break;
+ case OPT_EXPIRE: /* --expire */
+ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+ break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ exit(1);
+ default:
+ abort();
+ }
+ }
+}
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <getopt.h>\r
-#include <memcached.h>\r
-#include "client_options.h"\r
-#include "utilities.h"\r
-\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
- 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
- \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
- 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
- if (option_rv == -1) break;\r
- switch (option_rv)\r
- {\r
- case 0:\r
- break;\r
- case OPT_VERBOSE: /* --verbose or -v */\r
- opt_verbose = OPT_VERBOSE;\r
- break;\r
- case OPT_DEBUG: /* --debug or -d */\r
- opt_verbose = OPT_DEBUG;\r
- break;\r
- case OPT_VERSION: /* --version or -V */\r
- printf("memcache tools, memrm, v1.0\n");\r
- exit(0);\r
- break;\r
- case OPT_HELP: /* --help or -h */\r
- printf("useful help messages go here\n");\r
- exit(0);\r
- break;\r
- case OPT_SERVERS: /* --servers or -s */\r
- opt_servers= strdup(optarg);\r
- break;\r
- case OPT_EXPIRE: /* --expire */\r
- opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);\r
- break;\r
- case '?':\r
- /* getopt_long already printed an error message. */\r
- exit(1);\r
- default:\r
- abort();\r
- }\r
- }\r
-}\r
+#include <stdio.h>
+#include <unistd.h>
+#include <getopt.h>
+#include <memcached.h>
+#include "client_options.h"
+#include "utilities.h"
+
+static int opt_verbose= 0;
+static time_t opt_expire= 0;
+static char *opt_servers= NULL;
+
+/* Prototypes */
+void options_parse(int argc, char *argv[]);
+
+int main(int argc, char *argv[])
+{
+ memcached_st *memc;
+ memcached_return rc;
+
+ options_parse(argc, argv);
+
+ memc= memcached_init(NULL);
+
+ if (opt_servers)
+ parse_opt_servers(memc, opt_servers);
+
+ 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);
+
+ if (rc != MEMCACHED_SUCCESS)
+ {
+ fprintf(stderr, "memrm: %s: memcache error %s\n",
+ argv[optind], memcached_strerror(memc, rc));
+ }
+
+ optind++;
+ }
+
+ memcached_deinit(memc);
+
+ free(opt_servers);
+
+ return 0;
+}
+
+
+void options_parse(int argc, char *argv[])
+{
+ static struct option long_options[]=
+ {
+ {"version", no_argument, NULL, OPT_VERSION},
+ {"help", no_argument, NULL, OPT_HELP},
+ {"verbose", no_argument, &opt_verbose, OPT_VERBOSE},
+ {"debug", no_argument, &opt_verbose, OPT_DEBUG},
+ {"servers", required_argument, NULL, OPT_SERVERS},
+ {"expire", required_argument, NULL, OPT_EXPIRE},
+ {0, 0, 0, 0},
+ };
+ int option_index= 0;
+ int option_rv;
+
+ while (1)
+ {
+ option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index);
+ if (option_rv == -1) break;
+ switch (option_rv)
+ {
+ case 0:
+ break;
+ case OPT_VERBOSE: /* --verbose or -v */
+ opt_verbose = OPT_VERBOSE;
+ break;
+ case OPT_DEBUG: /* --debug or -d */
+ opt_verbose = OPT_DEBUG;
+ break;
+ case OPT_VERSION: /* --version or -V */
+ printf("memcache tools, memrm, v1.0\n");
+ exit(0);
+ break;
+ case OPT_HELP: /* --help or -h */
+ printf("useful help messages go here\n");
+ exit(0);
+ break;
+ case OPT_SERVERS: /* --servers or -s */
+ opt_servers= strdup(optarg);
+ break;
+ case OPT_EXPIRE: /* --expire */
+ opt_expire= (time_t)strtoll(optarg, (char **)NULL, 10);
+ break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ exit(1);
+ default:
+ abort();
+ }
+ }
+}
#include <ctype.h>
+#include <strings.h>
#include <memcached.h>
void parse_opt_servers(memcached_st *memc,
-INCLUDES = -I$(top_builddir)/include\r
-LDADDS = ../lib/libmemcached.la\r
-\r
-EXTRA_DIST = output.res output2.res\r
-\r
-LIBS = \r
-\r
-noinst_PROGRAMS = testapp\r
-\r
-testapp_SOURCES = test.c\r
-testapp_LDADD = $(LDADDS)\r
-\r
-record:\r
- ./testapp > output.res\r
-\r
-record-extended:\r
- ./testapp extended > output2.res\r
-\r
-test: testapp\r
- ./testapp > output.cmp\r
- diff output.res output.cmp\r
-\r
-test-extended: testapp\r
- ./testapp extended > output.cmp\r
- diff output2.res output.cmp\r
-\r
-valgrind:\r
- libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp\r
-\r
-valgrind-extended:\r
- libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp extended\r
+INCLUDES = -I$(top_builddir)/include
+LDADDS = ../lib/libmemcached.la
+
+EXTRA_DIST = output.res output2.res
+
+LIBS =
+
+noinst_PROGRAMS = testapp
+
+testapp_SOURCES = test.c
+testapp_LDADD = $(LDADDS)
+
+record:
+ ./testapp > output.res
+
+record-extended:
+ ./testapp extended > output2.res
+
+test: testapp
+ ./testapp > output.cmp
+ diff output.res output.cmp
+
+test-extended: testapp
+ ./testapp extended > output.cmp
+ diff output2.res output.cmp
+
+valgrind:
+ libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp
+
+valgrind-extended:
+ libtool --mode=execute valgrind --leak-check=yes --show-reachable=yes testapp extended
memcached_st *memc;
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
assert(memc);
memcached_deinit(memc);
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_add(memc, key, strlen(key),
value, strlen(value),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_replace(memc, key, strlen(key),
value, strlen(value),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
value, strlen(value),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_flush(memc, 0);
assert(rc == MEMCACHED_SUCCESS);
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
string= memcached_get(memc, key, strlen(key),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
char *string;
size_t string_length;
uint16_t flags;
- int i;
+ int x;
- value = (char*) malloc(value_length);
- for (i=0; i<value_length; i++)
- value[i] = (char) (i % 127);
+ value = (char*)malloc(value_length);
+ assert(value);
+
+ for (x= 0; x < value_length; x++)
+ value[x] = (char) (x % 127);
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
string= memcached_get(memc, key, strlen(key),
&string_length, &flags, &rc);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(string);
assert(string_length == value_length);
assert(!memcmp(string, value, string_length));
memcached_return rc;
memcached_stat_st stat;
rc= memcached_stat_servername(&stat, NULL,
- "localhost",
+ "zim.tangent.org",
MEMCACHED_DEFAULT_PORT);
}
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
rc= memcached_set(memc, key, strlen(key),
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
/* We need to empty the server before continueing test */
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
stat= memcached_stat(memc, NULL, &rc);
memc= memcached_init(NULL);
assert(memc);
- rc= memcached_server_add(memc, "localhost", 0);
+ rc= memcached_server_add(memc, "zim.tangent.org", 0);
assert(rc == MEMCACHED_SUCCESS);
- rc= memcached_server_add(memc, "localhost", 5555);
+ rc= memcached_server_add(memc, "zim.tangent.org", 5555);
assert(rc == MEMCACHED_SUCCESS);
stat= memcached_stat(memc, NULL, &rc);