X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached_response.c;h=10547504743c476956ade3a7a5ebfe664f44aa4c;hb=d6505b16fb85f77527934510d0395adfcbb66377;hp=99020559dfd57de419ce7daeaf3daae3ba367e86;hpb=1fc4b1ae18810551553837b4c67c6075f1ad5941;p=m6w6%2Flibmemcached diff --git a/lib/memcached_response.c b/lib/memcached_response.c index 99020559..10547504 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -5,50 +5,90 @@ from an issued command. */ -#include +#include "common.h" +#include "memcached_io.h" memcached_return memcached_response(memcached_st *ptr, - char *buffer, size_t buffer_length) + char *buffer, size_t buffer_length, + unsigned int server_key) { + unsigned int x; size_t send_length; + char *buffer_ptr; + unsigned int max_messages; + memset(buffer, 0, buffer_length); - send_length= read(ptr->hosts[0].fd, buffer, buffer_length); + send_length= 0; + + max_messages= memcached_server_response_count(ptr, server_key); + for (x= 0; x <= max_messages; x++) + { + buffer_ptr= buffer; + + while (1) + { + unsigned int read_length; + + read_length= memcached_io_read(ptr, server_key, + buffer_ptr, 1); + + if (read_length != 1) + return MEMCACHED_UNKNOWN_READ_FAILURE; + + if (*buffer_ptr == '\n') + break; + else + buffer_ptr++; + } + + if (memcached_server_response_count(ptr, server_key)) + memcached_server_response_decrement(ptr, server_key); + } - if (send_length) - switch(buffer[0]) + switch(buffer[0]) + { + case 'V': /* VALUE */ + return MEMCACHED_SUCCESS; + case 'O': /* OK */ + return MEMCACHED_SUCCESS; + case 'S': /* STORED STATS SERVER_ERROR */ + { + if (buffer[2] == 'A') /* STORED STATS */ + return MEMCACHED_STAT; + else if (buffer[1] == 'E') + return MEMCACHED_SERVER_ERROR; + else if (buffer[1] == 'T') + return MEMCACHED_STORED; + else + return MEMCACHED_UNKNOWN_READ_FAILURE; + } + case 'D': /* DELETED */ + return MEMCACHED_DELETED; + case 'N': /* NOT_FOUND */ { - case 'V': /* VALUE */ - return MEMCACHED_SUCCESS; - case 'O': /* OK */ - return MEMCACHED_SUCCESS; - case 'S': /* STORED STATS SERVER_ERROR */ - { - if (buffer[1] == 'T') /* STORED STATS */ - return MEMCACHED_SUCCESS; - else if (buffer[1] == 'E') - return MEMCACHED_SERVER_ERROR; - else - return MEMCACHED_UNKNOWN_READ_FAILURE; - } - case 'D': /* DELETED */ - return MEMCACHED_SUCCESS; - case 'N': /* NOT_FOUND */ - { - if (buffer[4] == 'F') - return MEMCACHED_NOTFOUND; - else if (buffer[4] == 'S') - return MEMCACHED_NOTSTORED; - else - return MEMCACHED_UNKNOWN_READ_FAILURE; - } - case 'E': /* PROTOCOL ERROR */ - return MEMCACHED_PROTOCOL_ERROR; - case 'C': /* CLIENT ERROR */ - return MEMCACHED_CLIENT_ERROR; - default: - return MEMCACHED_UNKNOWN_READ_FAILURE; + if (buffer[4] == 'F') + return MEMCACHED_NOTFOUND; + else if (buffer[4] == 'S') + return MEMCACHED_NOTSTORED; + else + return MEMCACHED_UNKNOWN_READ_FAILURE; } + case 'E': /* PROTOCOL ERROR or END */ + { + if (buffer[1] == 'N') + return MEMCACHED_END; + else if (buffer[1] == 'R') + return MEMCACHED_PROTOCOL_ERROR; + else + return MEMCACHED_UNKNOWN_READ_FAILURE; + } + case 'C': /* CLIENT ERROR */ + return MEMCACHED_CLIENT_ERROR; + default: + return MEMCACHED_UNKNOWN_READ_FAILURE; + + } - return MEMCACHED_READ_FAILURE; + return MEMCACHED_SUCCESS; }