X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached_response.c;h=1276351332d829d851eab826fe4ce61f540465ed;hb=a95ca4ad9c0f9d23c8a83bd337acdecc221021ef;hp=1d0937af7999f6005ba677b798eccf55e32c2808;hpb=452f5b545eec58ac1bddd32ea131b79e2b1a52a9;p=awesomized%2Flibmemcached diff --git a/lib/memcached_response.c b/lib/memcached_response.c index 1d0937af..12763513 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -5,7 +5,7 @@ from an issued command. */ -#include +#include "common.h" memcached_return memcached_response(memcached_st *ptr, char *buffer, size_t buffer_length, @@ -15,12 +15,13 @@ memcached_return memcached_response(memcached_st *ptr, char *buffer_ptr; memset(buffer, 0, buffer_length); + send_length= 0; buffer_ptr= buffer; while (1) { unsigned int read_length; - read_length= read(ptr->hosts[server_key].fd, buffer_ptr, 1); + read_length= recv(ptr->hosts[server_key].fd, buffer_ptr, 1, 0); if (read_length != 1) return MEMCACHED_UNKNOWN_READ_FAILURE; @@ -31,47 +32,47 @@ memcached_return memcached_response(memcached_st *ptr, buffer_ptr++; } - 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[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 */ { - 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 or END */ - { - if (buffer[1] == 'N') - return MEMCACHED_NOTFOUND; - 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; + 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_NOTFOUND; + 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; }