Added/restructured all additional hostname information
[awesomized/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 "common.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 char *buffer_ptr;
16
17 memset(buffer, 0, buffer_length);
18 send_length= 0;
19
20 buffer_ptr= buffer;
21 while (1)
22 {
23 unsigned int read_length;
24 read_length= recv(ptr->hosts[server_key].fd, buffer_ptr, 1, 0);
25
26 if (read_length != 1)
27 return MEMCACHED_UNKNOWN_READ_FAILURE;
28
29 if (*buffer_ptr == '\n')
30 break;
31 else
32 buffer_ptr++;
33 }
34
35 switch(buffer[0])
36 {
37 case 'V': /* VALUE */
38 return MEMCACHED_SUCCESS;
39 case 'O': /* OK */
40 return MEMCACHED_SUCCESS;
41 case 'S': /* STORED STATS SERVER_ERROR */
42 {
43 if (buffer[1] == 'T') /* STORED STATS */
44 return MEMCACHED_SUCCESS;
45 else if (buffer[1] == 'E')
46 return MEMCACHED_SERVER_ERROR;
47 else
48 return MEMCACHED_UNKNOWN_READ_FAILURE;
49 }
50 case 'D': /* DELETED */
51 return MEMCACHED_DELETED;
52 case 'N': /* NOT_FOUND */
53 {
54 if (buffer[4] == 'F')
55 return MEMCACHED_NOTFOUND;
56 else if (buffer[4] == 'S')
57 return MEMCACHED_NOTSTORED;
58 else
59 return MEMCACHED_UNKNOWN_READ_FAILURE;
60 }
61 case 'E': /* PROTOCOL ERROR or END */
62 {
63 if (buffer[1] == 'N')
64 return MEMCACHED_END;
65 else if (buffer[1] == 'R')
66 return MEMCACHED_PROTOCOL_ERROR;
67 else
68 return MEMCACHED_UNKNOWN_READ_FAILURE;
69 }
70 case 'C': /* CLIENT ERROR */
71 return MEMCACHED_CLIENT_ERROR;
72 default:
73 return MEMCACHED_UNKNOWN_READ_FAILURE;
74
75 }
76
77 return MEMCACHED_SUCCESS;
78 }