Memory leak fixed.
[m6w6/libmemcached] / lib / memcached_response.c
1 /*
2 Memcached library
3
4 memcached_response() is used to determine the return result
5 from an issued command.
6 */
7
8 #include <memcached.h>
9
10 memcached_return memcached_response(memcached_st *ptr,
11 char *buffer, size_t buffer_length,
12 unsigned int server_key)
13 {
14 size_t send_length;
15
16 memset(buffer, 0, buffer_length);
17 send_length= read(ptr->hosts[server_key].fd, buffer, buffer_length);
18
19 if (send_length)
20 switch(buffer[0])
21 {
22 case 'V': /* VALUE */
23 return MEMCACHED_SUCCESS;
24 case 'O': /* OK */
25 return MEMCACHED_SUCCESS;
26 case 'S': /* STORED STATS SERVER_ERROR */
27 {
28 if (buffer[1] == 'T') /* STORED STATS */
29 return MEMCACHED_SUCCESS;
30 else if (buffer[1] == 'E')
31 return MEMCACHED_SERVER_ERROR;
32 else
33 return MEMCACHED_UNKNOWN_READ_FAILURE;
34 }
35 case 'D': /* DELETED */
36 return MEMCACHED_SUCCESS;
37 case 'N': /* NOT_FOUND */
38 {
39 if (buffer[4] == 'F')
40 return MEMCACHED_NOTFOUND;
41 else if (buffer[4] == 'S')
42 return MEMCACHED_NOTSTORED;
43 else
44 return MEMCACHED_UNKNOWN_READ_FAILURE;
45 }
46 case 'E': /* PROTOCOL ERROR */
47 return MEMCACHED_PROTOCOL_ERROR;
48 case 'C': /* CLIENT ERROR */
49 return MEMCACHED_CLIENT_ERROR;
50 default:
51 return MEMCACHED_UNKNOWN_READ_FAILURE;
52 }
53
54 return MEMCACHED_READ_FAILURE;
55 }