X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=lib%2Fmemcached_response.c;h=ce129aeed23ec125d121ee98270f6673e6747a3c;hb=ccd00450d57624afba24bfbb6e76d1d69d0ad0f8;hp=09d1fa4d8b91bc0a8725a69ad9ef1255a4745d50;hpb=1f34771f7ba527e3afb675f1a448d6c5ab66596b;p=m6w6%2Flibmemcached diff --git a/lib/memcached_response.c b/lib/memcached_response.c index 09d1fa4d..ce129aee 100644 --- a/lib/memcached_response.c +++ b/lib/memcached_response.c @@ -8,47 +8,71 @@ #include memcached_return memcached_response(memcached_st *ptr, - char *buffer, size_t buffer_length) + char *buffer, size_t buffer_length, + unsigned int server_key) { size_t send_length; + char *buffer_ptr; memset(buffer, 0, buffer_length); - send_length= read(ptr->fd, buffer, buffer_length); + send_length= 0; - if (send_length) - switch(buffer[0]) + buffer_ptr= buffer; + while (1) + { + unsigned int read_length; + read_length= recv(ptr->hosts[server_key].fd, buffer_ptr, 1, 0); + + if (read_length != 1) + return MEMCACHED_UNKNOWN_READ_FAILURE; + + if (*buffer_ptr == '\n') + break; + else + buffer_ptr++; + } + + 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 */ + { + 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 */ { - 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[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; }