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
;
23 max_messages
= memcached_server_response_count(ptr
, server_key
);
24 for (x
= 0; x
<= max_messages
; x
++)
26 size_t total_length
= 0;
31 unsigned int read_length
;
33 read_length
= memcached_io_read(ptr
, server_key
,
37 return MEMCACHED_UNKNOWN_READ_FAILURE
;
39 if (*buffer_ptr
== '\n')
45 WATCHPOINT_ASSERT(total_length
<= buffer_length
);
47 if (total_length
>= buffer_length
)
48 return MEMCACHED_PROTOCOL_ERROR
;
53 if (memcached_server_response_count(ptr
, server_key
))
54 memcached_server_response_decrement(ptr
, server_key
);
59 case 'V': /* VALUE || VERSION */
60 return MEMCACHED_SUCCESS
;
62 return MEMCACHED_SUCCESS
;
63 case 'S': /* STORED STATS SERVER_ERROR */
65 if (buffer
[2] == 'A') /* STORED STATS */
66 return MEMCACHED_STAT
;
67 else if (buffer
[1] == 'E')
68 return MEMCACHED_SERVER_ERROR
;
69 else if (buffer
[1] == 'T')
70 return MEMCACHED_STORED
;
72 return MEMCACHED_UNKNOWN_READ_FAILURE
;
74 case 'D': /* DELETED */
75 return MEMCACHED_DELETED
;
76 case 'N': /* NOT_FOUND */
79 return MEMCACHED_NOTFOUND
;
80 else if (buffer
[4] == 'S')
81 return MEMCACHED_NOTSTORED
;
83 return MEMCACHED_UNKNOWN_READ_FAILURE
;
85 case 'E': /* PROTOCOL ERROR or END */
89 else if (buffer
[1] == 'R')
90 return MEMCACHED_PROTOCOL_ERROR
;
92 return MEMCACHED_UNKNOWN_READ_FAILURE
;
94 case 'C': /* CLIENT ERROR */
95 return MEMCACHED_CLIENT_ERROR
;
97 return MEMCACHED_UNKNOWN_READ_FAILURE
;
101 return MEMCACHED_SUCCESS
;
104 char *memcached_result_value(memcached_result_st
*ptr
)
106 memcached_string_st
*sptr
= &ptr
->value
;
107 return memcached_string_value(sptr
);
110 size_t memcached_result_length(memcached_result_st
*ptr
)
112 memcached_string_st
*sptr
= &ptr
->value
;
113 return memcached_string_length(sptr
);