Broke library up into multiple files.
[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 {
13 size_t send_length;
14
15 memset(buffer, 0, buffer_length);
16 send_length= read(ptr->fd, buffer, buffer_length);
17
18 if (send_length)
19 switch(buffer[0])
20 {
21 case 'V': /* VALUE */
22 return MEMCACHED_SUCCESS;
23 case 'O': /* OK */
24 return MEMCACHED_SUCCESS;
25 case 'S': /* STORED STATS SERVER_ERROR */
26 {
27 if (buffer[1] == 'T') /* STORED STATS */
28 return MEMCACHED_SUCCESS;
29 else if (buffer[1] == 'E')
30 return MEMCACHED_SERVER_ERROR;
31 else
32 return MEMCACHED_UNKNOWN_READ_FAILURE;
33 }
34 case 'D': /* DELETED */
35 return MEMCACHED_SUCCESS;
36 case 'N': /* NOT_FOUND */
37 {
38 if (buffer[4] == 'F')
39 return MEMCACHED_NOTFOUND;
40 else if (buffer[4] == 'S')
41 return MEMCACHED_NOTSTORED;
42 else
43 return MEMCACHED_UNKNOWN_READ_FAILURE;
44 }
45 case 'E': /* PROTOCOL ERROR */
46 return MEMCACHED_PROTOCOL_ERROR;
47 case 'C': /* CLIENT ERROR */
48 return MEMCACHED_CLIENT_ERROR;
49 default:
50 return MEMCACHED_UNKNOWN_READ_FAILURE;
51 }
52
53 return MEMCACHED_READ_FAILURE;
54 }