From: Date: Fri, 7 Mar 2008 16:15:01 +0000 (-0500) Subject: Fixes for previous merges (and additional file added for murmur) X-Git-Tag: _20~1^2~67 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=89453bb8a7c9593c48635165b780918bc277c6c5;p=m6w6%2Flibmemcached Fixes for previous merges (and additional file added for murmur) --- diff --git a/ChangeLog b/ChangeLog index ff863160..9f77a0ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,17 @@ -0.17 - * MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT added for connect timeout in - non-block mode. +0.18 * Fix plus tests for non-zero value objects and flags. * MEMCACHED_HASH_MURMUR added for murmur algorithm provided. * MEMCACHED_BEHAVIOR_RETRY_TIMEOUT added to keep connecting from looping on timeout. +0.17 Wed Feb 27 03:33:29 PST 2008 + * MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT added for connect timeout in + non-block mode. + * Incompatible change in memcached_behavior_set() api. We now use a + uint64_t, instead of a pointer. + * Fix for storage of values for zero. + * memcached_server_cursor() function added to API for cycling through servers. + 0.16 Mon Feb 18 00:30:25 PST 2008 * Work on the UDP protocol * Added get_by_key, set_by_key tests for C++ API diff --git a/THANKS b/THANKS index 45809cec..35db5339 100644 --- a/THANKS +++ b/THANKS @@ -8,3 +8,4 @@ Tim Bunce - Perl Driver work and feedback on API Kevin Dalley - Bug Fixes Patrick Galbraith - work on C++ interface Ross McFarland - Idea for sorting servers. +Marcelo Fernandez - TCP/IP timeout pieces diff --git a/include/memcached.h b/include/memcached.h index afd43b41..3178866d 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -267,7 +267,7 @@ memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity); void memcached_quit(memcached_st *ptr); char *memcached_strerror(memcached_st *ptr, memcached_return rc); memcached_return memcached_behavior_set(memcached_st *ptr, memcached_behavior flag, void *data); -unsigned long long memcached_behavior_get(memcached_st *ptr, memcached_behavior flag); +uint64_t memcached_behavior_get(memcached_st *ptr, memcached_behavior flag); /* All of the functions for adding data to the server */ memcached_return memcached_set(memcached_st *ptr, char *key, size_t key_length, diff --git a/lib/memcached_connect.c b/lib/memcached_connect.c index 4bfc710f..dc86d1e1 100644 --- a/lib/memcached_connect.c +++ b/lib/memcached_connect.c @@ -1,4 +1,5 @@ #include "common.h" +#include static memcached_return set_hostinfo(memcached_server_st *server) { @@ -136,47 +137,6 @@ test_connect: { switch (errno) { case EINPROGRESS: - { - struct timeval tm = { ptr->root->connect_timeout, 0 }; - socklen_t len= sizeof(int); - fd_set wset; - int error=0, value; - - FD_ZERO(&wset); - FD_SET(ptr->fd, &wset); - - select(ptr->fd+1, NULL, &wset, NULL, &tm); - if (FD_ISSET(ptr->fd, &wset) != 0) - { - if (getsockopt(ptr->fd, SOL_SOCKET, SO_ERROR, &value, &len) == 0) - { - if (value) - { - error= 1; - } - } - else - { - error= 1; - } - } - else - { - error= 1; - } - - if (error) - { - ptr->cached_errno= errno; - WATCHPOINT_ERRNO(ptr->cached_errno); - close(ptr->fd); - ptr->fd= -1; - return MEMCACHED_ERRNO; - } - - break; - } - /* We are spinning waiting on connect */ case EALREADY: case EINTR: goto test_connect; @@ -237,6 +197,27 @@ test_connect: /* We are spinning waiting on connect */ case EALREADY: case EINPROGRESS: + { + struct pollfd fds[1]; + int error; + + memset(&fds, 0, sizeof(struct pollfd)); + fds[0].fd= ptr->fd; + fds[0].events= POLLOUT | POLLERR; + error= poll(fds, 1, ptr->root->connect_timeout); + + if (error != 1) + { + ptr->cached_errno= errno; + WATCHPOINT_ERRNO(ptr->cached_errno); + close(ptr->fd); + ptr->fd= -1; + return MEMCACHED_ERRNO; + } + + break; + } + /* We are spinning waiting on connect */ case EINTR: goto test_connect; case EISCONN: /* We were spinning waiting on connect */ diff --git a/lib/murmur_hash.c b/lib/murmur_hash.c new file mode 100644 index 00000000..abb2deda --- /dev/null +++ b/lib/murmur_hash.c @@ -0,0 +1,48 @@ +#include "common.h" + +/* + "Murmur"hash provided by Austin, tanjent@gmail.com +#define MURMUR_POSTMIX +*/ + +uint32_t murmur_hash(char *key, size_t length) +{ + const unsigned int m= 0x7fd652ad; + const int r= 16; + + uint32_t h= 0xdeadbeef; + + while(length >= 4) + { + h += *(unsigned int *)key; + h *= m; + h ^= h >> r; + + key += 4; + length -= 4; + } + + switch(length) + { + case 3: + h += key[2] << 16; + case 2: + h += key[1] << 8; + case 1: + default: + h += key[0]; + h *= m; + h ^= h >> r; + }; + +#ifdef MURMUR_POSTMIX + + h *= m; + h ^= h >> 10; + h *= m; + h ^= h >> 17; + +#endif + + return h; +} diff --git a/src/utilities.c b/src/utilities.c index 2094d218..2a63f9e5 100644 --- a/src/utilities.c +++ b/src/utilities.c @@ -75,7 +75,7 @@ void help_command(char *command_name, char *description, void process_hash_option(memcached_st *memc, char *opt_hash) { - unsigned int set; + uint64_t set; memcached_return rc; if (opt_hash == NULL) @@ -99,7 +99,7 @@ void process_hash_option(memcached_st *memc, char *opt_hash) exit(1); } - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, &set); + rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_HASH, set); if (rc != MEMCACHED_SUCCESS) { fprintf(stderr, "hash: memcache error %s\n", memcached_strerror(memc, rc));