From 686192d8ff24bcc24d3ea9d1aa49373fb2bb198c Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 19 Oct 2007 15:18:10 -0700 Subject: [PATCH] Big change, we use poll() now instead of select() 1) It is faster. 2) I think this means bye bye to the random write failure. Difference? select(): Testing user_supplied_bug1 3.512 [ ok ] Testing user_supplied_bug2 3.461 [ ok ] poll(): Testing user_supplied_bug1 1.324 [ ok ] Testing user_supplied_bug2 1.303 [ ok ] This commit also update variables for next release. --- ChangeLog | 3 ++ configure.in | 2 +- lib/memcached_io.c | 105 ++++++++++++++++++++++---------------- support/libmemcached.spec | 2 +- 4 files changed, 65 insertions(+), 47 deletions(-) diff --git a/ChangeLog b/ChangeLog index be55ed74..ed287957 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +0.7 + * Poved to poll() from select() + 0.6 Wed Oct 17 08:41:35 PDT 2007 * get value returns are now null terminated (request by Cal Heldenbrand) * Fixed connections for more hosts then two. diff --git a/configure.in b/configure.in index 79c91a74..b6b849d4 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ AC_INIT(src/memcat.c) AC_CONFIG_AUX_DIR(config) AM_CONFIG_HEADER(include/libmemcached_config.h) -AM_INIT_AUTOMAKE("libmemcached", 0.6) +AM_INIT_AUTOMAKE("libmemcached", 0.7) AC_PROG_CC AC_PROG_LIBTOOL diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 54a4b8dc..45a12199 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -5,6 +5,58 @@ #include "common.h" #include "memcached_io.h" #include +#include + +int io_wait(memcached_st *ptr, unsigned int server_key, unsigned read_or_write) +{ + struct pollfd fds[1]; + short flags= 0; + + if (read_or_write) + flags= POLLOUT | POLLERR; + else + flags= POLLIN | POLLERR; + + memset(&fds, 0, sizeof(struct pollfd)); + fds[0].fd= ptr->hosts[server_key].fd; + fds[0].events= flags; + + if (poll(fds, 1, -1) < 0) + return MEMCACHED_FAILURE; + + return MEMCACHED_SUCCESS; +#ifdef OLD + while (1) + { + int select_return; + struct timeval local_tv; + fd_set set; + + memset(&local_tv, 0, sizeof(struct timeval)); + + local_tv.tv_sec= 0; + local_tv.tv_usec= 300; + + FD_ZERO(&set); + FD_SET(ptr->hosts[server_key].fd, &set); + + if (read_or_write) + select_return= select(1, &set, NULL, NULL, &local_tv); + else + select_return= select(1, NULL, &set, NULL, &local_tv); + + if (select_return == -1) + { + ptr->my_errno= errno; + return MEMCACHED_FAILURE; + } + else if (!select_return) + break; + } + + return MEMCACHED_SUCCESS; +#endif +} ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, char *buffer, size_t length) @@ -23,30 +75,11 @@ ssize_t memcached_io_read(memcached_st *ptr, unsigned int server_key, { if (ptr->flags & MEM_NO_BLOCK) { - while (1) - { - int select_return; - struct timeval local_tv; - fd_set set; + memcached_return rc; - memset(&local_tv, 0, sizeof(struct timeval)); - - local_tv.tv_sec= 0; - local_tv.tv_usec= 300; - - FD_ZERO(&set); - FD_SET(ptr->hosts[server_key].fd, &set); - - select_return= select(1, &set, NULL, NULL, &local_tv); - - if (select_return == -1) - { - ptr->my_errno= errno; - return -1; - } - else if (!select_return) - break; - } + rc= io_wait(ptr, server_key, 0); + if (rc != MEMCACHED_SUCCESS) + return -1; } data_read= recv(ptr->hosts[server_key].fd, @@ -128,29 +161,11 @@ ssize_t memcached_io_flush(memcached_st *ptr, unsigned int server_key) { if (ptr->flags & MEM_NO_BLOCK) { + memcached_return rc; - while (1) - { - struct timeval local_tv; - fd_set set; - int select_return; - - local_tv.tv_sec= 0; - local_tv.tv_usec= 300 * loop; - - FD_ZERO(&set); - FD_SET(ptr->hosts[server_key].fd, &set); - - select_return= select(1, NULL, &set, NULL, &local_tv); - - if (select_return == -1) - { - ptr->my_errno= errno; - return -1; - } - else if (!select_return) - break; - } + rc= io_wait(ptr, server_key, 1); + if (rc != MEMCACHED_SUCCESS) + return -1; } sent_length= 0; diff --git a/support/libmemcached.spec b/support/libmemcached.spec index 67ccbb63..f5880308 100644 --- a/support/libmemcached.spec +++ b/support/libmemcached.spec @@ -1,6 +1,6 @@ Summary: memcached C library and command line tools Name: libmemcached -Version: 0.6 +Version: 0.7 Release: 1 License: BSD Group: System Environment/Libraries -- 2.30.2