From: Brian Aker Date: Tue, 29 Jan 2008 07:42:27 +0000 (-0800) Subject: Fix for non-blocking IO error. The refactoring bit broke some cases where X-Git-Tag: 0.15~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6dab216a486ce3c5cb9a041f91bedb88afc8515a;p=awesomized%2Flibmemcached Fix for non-blocking IO error. The refactoring bit broke some cases where the server had not caught up with the client. --- diff --git a/include/memcached.h b/include/memcached.h index eddc5f3c..62996333 100644 --- a/include/memcached.h +++ b/include/memcached.h @@ -433,7 +433,7 @@ size_t memcached_result_length(memcached_result_st *ptr); #define WATCHPOINT_STRING(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); #define WATCHPOINT_STRING_LENGTH(A,B) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); #define WATCHPOINT_NUMBER(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); -#define WATCHPOINT_ERRNO(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));A= 0;fflush(stdout); +#define WATCHPOINT_ERRNO(A) fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); #define WATCHPOINT_ASSERT(A) assert((A)); #else #define WATCHPOINT diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 22c54e42..bb53f08e 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -86,14 +86,14 @@ ssize_t memcached_io_read(memcached_server_st *ptr, uint8_t found_eof= 0; if (!ptr->read_buffer_length) { - size_t data_read; + ssize_t data_read; while (1) { data_read= read(ptr->fd, ptr->read_buffer, MEMCACHED_MAX_BUFFER); - if (data_read) + if (data_read > 0) break; else if (data_read == -1) { diff --git a/lib/memcached_response.c b/lib/memcached_response.c index 4b29a1cb..95610793 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -32,9 +32,10 @@ memcached_return memcached_response(memcached_server_st *ptr, while (1) { - unsigned int read_length; + ssize_t read_length; read_length= memcached_io_read(ptr, buffer_ptr, 1); + WATCHPOINT_ASSERT(isgraph(*buffer_ptr) || isspace(*buffer_ptr)); if (read_length != 1) return MEMCACHED_UNKNOWN_READ_FAILURE; diff --git a/tests/function.c b/tests/function.c index 8592e550..a1c817a4 100644 --- a/tests/function.c +++ b/tests/function.c @@ -392,6 +392,12 @@ uint8_t replace_test(memcached_st *memc) memcached_return rc; char *key= "foo"; char *value= "when we sanitize"; + char *original= "first we insert some data"; + + rc= memcached_set(memc, key, strlen(key), + original, strlen(original), + (time_t)0, (uint32_t)0); + assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); rc= memcached_replace(memc, key, strlen(key), value, strlen(value), @@ -2312,7 +2318,7 @@ test_st tests[] ={ {"set2", 0, set_test2 }, {"set3", 0, set_test3 }, {"add", 1, add_test }, - {"replace", 0, replace_test }, + {"replace", 1, replace_test }, {"delete", 1, delete_test }, {"get", 1, get_test }, {"get2", 0, get_test2 },