X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fmemcapable.cc;h=8bce153a555e44ffa9136d5c8e30f7a6194025bb;hb=2740396a3a5535f65b917ba858eef8c5a5ae07b3;hp=99ca5ea77c30cda16e953e6caa8a24a05ae1a9a9;hpb=bc8deb7c59cf022024cff1de478fa389dd4cec31;p=awesomized%2Flibmemcached diff --git a/clients/memcapable.cc b/clients/memcapable.cc index 99ca5ea7..8bce153a 100644 --- a/clients/memcapable.cc +++ b/clients/memcapable.cc @@ -12,25 +12,32 @@ /* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */ #undef NDEBUG -#include "config.h" -#include -#include +#include + +#ifdef HAVE_POLL_H +#include +#else +#include "poll/poll.h" +#endif + +#include +#include +#include +#include +#include +#include #include -#include -#include -#include -#include -#include -#include #include -#include +#include +#include +#include #include -#include -#include +#include +#include #include #include -#include "utilities.h" +#include #ifdef linux /* /usr/include/netinet/in.h defines macros from ntohs() to _bswap_nn to @@ -126,7 +133,7 @@ static memcached_socket_t set_noblock(void) if (flags == -1) { perror("Failed to get socket flags"); - closesocket(sock); + memcached_close_socket(sock); return INVALID_SOCKET; } @@ -135,7 +142,7 @@ static memcached_socket_t set_noblock(void) if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) == -1) { perror("Failed to set socket to nonblocking mode"); - closesocket(sock); + memcached_close_socket(sock); return INVALID_SOCKET; } } @@ -1329,7 +1336,10 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ verify(strncmp(buffer, "VALUE ", 6) == 0); char *end= strchr(buffer + 6, ' '); verify(end != NULL); - *end= '\0'; + if (end) + { + *end= '\0'; + } *key= strdup(buffer + 6); verify(*key != NULL); char *ptr= end + 1; @@ -1341,9 +1351,9 @@ static enum test_return ascii_get_unknown_value(char **key, char **value, ssize_ *ndata = (ssize_t)strtoul(end, &end, 10); /* size */ verify(ptr != end); verify(end != NULL); - while (*end != '\n' && isspace(*end)) + while (end and *end != '\n' and isspace(*end)) ++end; - verify(*end == '\n'); + verify(end and *end == '\n'); *value= static_cast(malloc((size_t)*ndata)); verify(*value != NULL); @@ -1377,9 +1387,11 @@ static enum test_return ascii_get_value(const char *key, const char *value) verify(ptr != end); verify(val == datasize); verify(end != NULL); - while (*end != '\n' && isspace(*end)) + while (end and *end != '\n' and isspace(*end)) + { ++end; - verify(*end == '\n'); + } + verify(end and *end == '\n'); execute(retry_read(buffer, datasize)); verify(memcmp(buffer, value, datasize) == 0); @@ -1438,9 +1450,11 @@ static enum test_return ascii_gets_value(const char *key, const char *value, verify(val == datasize); verify(end != NULL); - while (*end != '\n' && isspace(*end)) + while (end and *end != '\n' and isspace(*end)) + { ++end; - verify(*end == '\n'); + } + verify(end and *end == '\n'); execute(retry_read(buffer, datasize)); verify(memcmp(buffer, value, datasize) == 0); @@ -1967,17 +1981,19 @@ int main(int argc, char **argv) - while ((cmd= getopt(argc, argv, "t:vch:p:PT:?ab")) != EOF) + while ((cmd= getopt(argc, argv, "qt:vch:p:PT:?ab")) != EOF) { switch (cmd) { case 'a': tests.ascii= true; tests.binary= false; break; + case 'b': tests.ascii= false; tests.binary= true; break; + case 't': timeout= atoi(optarg); if (timeout == 0) @@ -1986,18 +2002,29 @@ int main(int argc, char **argv) return EXIT_FAILURE; } break; + case 'v': verbose= true; break; + case 'c': do_core= true; break; + case 'h': hostname= optarg; break; + case 'p': port= optarg; break; + + case 'q': + close_stdio(); + break; + case 'P': prompt= true; break; + case 'T': testname= optarg; break; + default: fprintf(stderr, "Usage: %s [-h hostname] [-p port] [-c] [-v] [-t n] [-P] [-T testname]'\n" "\t-c\tGenerate coredump if a test fails\n"