From: Trond Norbye Date: Wed, 21 Jan 2009 10:03:42 +0000 (+0100) Subject: Added new command: memcached_flush_buffers X-Git-Tag: 0.26~12 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=cd2305940e0234791bbf26f53eca978076414ae7;p=awesomized%2Flibmemcached Added new command: memcached_flush_buffers --- diff --git a/docs/Makefile.am b/docs/Makefile.am index 1ca0652d..e21650e8 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -23,7 +23,8 @@ EXTRA_DIST = libmemcached.pod\ memcached_delete.pod\ memcached_set.pod\ memcached_version.pod\ - memflush.pod + memflush.pod\ + memcached_flush_buffers.pod man_MANS = libmemcached.3\ libmemcached_examples.3\ @@ -80,7 +81,8 @@ man_MANS = libmemcached.3\ memcached_quit.3\ memcached_verbosity.3\ memcached_lib_version.3\ - memcached_version.3 + memcached_version.3\ + memcached_flush_buffers.3 libmemcached.3: libmemcached.pod @POD2MAN@ -c "libmemcached" -r "" -s 3 libmemcached.pod > libmemcached.3 @@ -262,6 +264,9 @@ memcached_version.3: memcached_version.pod memcached_lib_version.3: memcached_version.pod @POD2MAN@ -c "libmemcached" -r "" -s 3 memcached_version.pod > memcached_lib_version.3 +memcached_flush_buffers.3: memcached_flush_buffers.pod + @POD2MAN@ -c "libmemcached" -r "" -s 3 memcached_flush_buffers.pod > memcached_flush_buffers.3 + memcp.1: memcp.pod @POD2MAN@ -c "libmemcached" -r "" -s 1 memcp.pod > memcp.1 @@ -308,7 +313,7 @@ test: podchecker memcached_set.pod podchecker memcached_version.pod podchecker memflush.pod - + podchecker memcached_flush_buffers.pod html: pod2htmltree "/libmemcached" . diff --git a/docs/memcached_behavior.pod b/docs/memcached_behavior.pod index f4246556..2ff1fb97 100755 --- a/docs/memcached_behavior.pod +++ b/docs/memcached_behavior.pod @@ -162,9 +162,7 @@ data, but the send will block because the input buffer in the kernel is full). =item MEMCACHED_BEHAVIOR_NOREPLY Set this value to specify that you really don't care about the result -from your storage commands (set, add, replace, append, prepend). With -this flag enabled, each storage request will be sent immediately to the -server overriding any setting of MEMCACHED_BEHAVIOR_BUFFER_REQUESTS. +from your storage commands (set, add, replace, append, prepend). =back diff --git a/docs/memcached_flush_buffers.pod b/docs/memcached_flush_buffers.pod new file mode 100755 index 00000000..4ed1aec2 --- /dev/null +++ b/docs/memcached_flush_buffers.pod @@ -0,0 +1,42 @@ +=head1 NAME + +memcached_flush_buffers + +=head1 LIBRARY + +C Client Library for memcached (libmemcached, -lmemcached) + +=head1 SYNOPSIS + + #include + + memcached_return + memcached_flush_buffers (memcached_st *ptr); + +=head1 DESCRIPTION + +memcached_flush_buffers() is used in conjunction with +MEMCACHED_BEHAVIOR_BUFFER_REQUESTS (see memcached_behavior(3)) to flush +all buffers by sending the buffered commands to the server for processing.. + +=head1 RETURN + +A value of type C is returned +On success that value will be C. +Use memcached_strerror() to translate this value to a printable string. + +=head1 HOME + +To find out more information please check: +L + +=head1 AUTHOR + +Trond Norbye, Etrond.norbye@sun.comE + +=head1 SEE ALSO + +memcached(1) libmemcached(3) memcached_strerror(3) memcached_behavior(3) + +=cut + diff --git a/libmemcached/Makefile.am b/libmemcached/Makefile.am index 78c2c9a1..bb5a483c 100644 --- a/libmemcached/Makefile.am +++ b/libmemcached/Makefile.am @@ -45,6 +45,7 @@ libmemcached_la_SOURCES = crc.c \ memcached_hosts.c \ memcached_io.c \ memcached_purge.c \ + memcached_flush_buffers.c \ md5.c \ memcached_key.c \ memcached_quit.c \ diff --git a/libmemcached/memcached_flush_buffers.c b/libmemcached/memcached_flush_buffers.c new file mode 100644 index 00000000..0a0fffb6 --- /dev/null +++ b/libmemcached/memcached_flush_buffers.c @@ -0,0 +1,13 @@ +#include "common.h" +#include "memcached_io.h" + +memcached_return memcached_flush_buffers(memcached_st *mem) +{ + memcached_return ret= MEMCACHED_SUCCESS; + + for (int x= 0; x < mem->number_of_hosts; ++x) + if (memcached_io_write(&mem->hosts[x], NULL, 0, 1) == -1) + ret= MEMCACHED_SOME_ERRORS; + + return ret; +} diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index 0f817c47..0b8a7685 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -127,14 +127,14 @@ static inline memcached_return memcached_send(memcached_st *ptr, if (ptr->flags & MEM_NOREPLY) { if (memcached_io_write(&ptr->hosts[server_key], " noreply\r\n", - 10, 1) == -1) + 10, to_write) == -1) { rc= MEMCACHED_WRITE_FAILURE; goto error; } memcached_server_response_decrement(&ptr->hosts[server_key]); - return MEMCACHED_SUCCESS; + return (to_write == 0) ? MEMCACHED_BUFFERED : MEMCACHED_SUCCESS; } if ((sent_length= memcached_io_write(&ptr->hosts[server_key], "\r\n", 2, to_write)) == -1) @@ -392,17 +392,6 @@ static memcached_return memcached_send_binary(memcached_server_st* server, flush= ((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1; - /* The binary protocol does not implement NOREPLY right now, so I need to - * parse the return message from the server. The problem we tried to solve - * is the fact that the async mode will buffer commands, and if we issue a - * lot of sets followed by a get we have to flush the send buffer before we - * can send the get command (and all those commands have to be executed). - * The workaround for the binary is that we send the command, but we await - * parsing of the result message until we really need to do it.. - */ - if (server->root->flags & MEM_NOREPLY) - flush=1; - /* write the header */ if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) || (memcached_io_write(server, key, key_length, 0) == -1) || @@ -412,7 +401,7 @@ static memcached_return memcached_send_binary(memcached_server_st* server, return MEMCACHED_WRITE_FAILURE; } - if (flush == 0 || server->root->flags & MEM_NOREPLY) + if (flush == 0) return MEMCACHED_BUFFERED; return memcached_response(server, NULL, 0, NULL); diff --git a/tests/function.c b/tests/function.c index e72dc7ee..a16ce773 100644 --- a/tests/function.c +++ b/tests/function.c @@ -3067,6 +3067,7 @@ static memcached_return noreply_test(memcached_st *memc) else assert(no_msg == 0); + assert(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS); return MEMCACHED_SUCCESS; }