4 memcached_response() is used to determine the return result
5 from an issued command.
9 #include "memcached_io.h"
11 memcached_return
memcached_response(memcached_st
*ptr
,
12 char *buffer
, size_t buffer_length
,
13 unsigned int server_key
)
18 unsigned int max_messages
;
21 memset(buffer
, 0, buffer_length
);
24 max_messages
= memcached_server_response_count(ptr
, server_key
);
25 for (x
= 0; x
<= max_messages
; x
++)
27 size_t total_length
= 0;
32 unsigned int read_length
;
34 read_length
= memcached_io_read(ptr
, server_key
,
38 return MEMCACHED_UNKNOWN_READ_FAILURE
;
40 if (*buffer_ptr
== '\n')
46 assert(total_length
< buffer_length
);
49 if (memcached_server_response_count(ptr
, server_key
))
50 memcached_server_response_decrement(ptr
, server_key
);
56 return MEMCACHED_SUCCESS
;
58 return MEMCACHED_SUCCESS
;
59 case 'S': /* STORED STATS SERVER_ERROR */
61 if (buffer
[2] == 'A') /* STORED STATS */
62 return MEMCACHED_STAT
;
63 else if (buffer
[1] == 'E')
64 return MEMCACHED_SERVER_ERROR
;
65 else if (buffer
[1] == 'T')
66 return MEMCACHED_STORED
;
68 return MEMCACHED_UNKNOWN_READ_FAILURE
;
70 case 'D': /* DELETED */
71 return MEMCACHED_DELETED
;
72 case 'N': /* NOT_FOUND */
75 return MEMCACHED_NOTFOUND
;
76 else if (buffer
[4] == 'S')
77 return MEMCACHED_NOTSTORED
;
79 return MEMCACHED_UNKNOWN_READ_FAILURE
;
81 case 'E': /* PROTOCOL ERROR or END */
85 else if (buffer
[1] == 'R')
86 return MEMCACHED_PROTOCOL_ERROR
;
88 return MEMCACHED_UNKNOWN_READ_FAILURE
;
90 case 'C': /* CLIENT ERROR */
91 return MEMCACHED_CLIENT_ERROR
;
93 return MEMCACHED_UNKNOWN_READ_FAILURE
;
97 return MEMCACHED_SUCCESS
;