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 memcached_result_st
*result
,
14 unsigned int server_key
)
19 unsigned int max_messages
;
24 /* We may have old commands in the buffer not set, first purge */
25 if (ptr
->flags
& MEM_NO_BLOCK
)
26 (void)memcached_io_write(ptr
, server_key
, NULL
, 0, 1);
28 max_messages
= memcached_server_response_count(ptr
, server_key
);
29 for (x
= 0; x
< max_messages
; x
++)
31 size_t total_length
= 0;
36 unsigned int read_length
;
38 read_length
= memcached_io_read(ptr
, server_key
,
42 return MEMCACHED_UNKNOWN_READ_FAILURE
;
44 if (*buffer_ptr
== '\n')
50 WATCHPOINT_ASSERT(total_length
<= buffer_length
);
52 if (total_length
>= buffer_length
)
53 return MEMCACHED_PROTOCOL_ERROR
;
58 memcached_server_response_decrement(ptr
, server_key
);
63 case 'V': /* VALUE || VERSION */
64 if (buffer
[1] == 'A') /* VALUE */
68 /* We add back in one because we will need to search for END */
69 memcached_server_response_increment(ptr
, server_key
);
71 rc
= value_fetch(ptr
, buffer
, result
, server_key
);
73 rc
= value_fetch(ptr
, buffer
, &ptr
->result
, server_key
);
77 else if (buffer
[1] == 'E') /* VERSION */
79 return MEMCACHED_SUCCESS
;
83 WATCHPOINT_STRING(buffer
);
85 return MEMCACHED_UNKNOWN_READ_FAILURE
;
88 return MEMCACHED_SUCCESS
;
89 case 'S': /* STORED STATS SERVER_ERROR */
91 if (buffer
[2] == 'A') /* STORED STATS */
93 memcached_server_response_increment(ptr
, server_key
);
94 return MEMCACHED_STAT
;
96 else if (buffer
[1] == 'E')
97 return MEMCACHED_SERVER_ERROR
;
98 else if (buffer
[1] == 'T')
99 return MEMCACHED_STORED
;
102 WATCHPOINT_STRING(buffer
);
103 WATCHPOINT_ASSERT(0);
104 return MEMCACHED_UNKNOWN_READ_FAILURE
;
107 case 'D': /* DELETED */
108 return MEMCACHED_DELETED
;
109 case 'N': /* NOT_FOUND */
111 if (buffer
[4] == 'F')
112 return MEMCACHED_NOTFOUND
;
113 else if (buffer
[4] == 'S')
114 return MEMCACHED_NOTSTORED
;
116 return MEMCACHED_UNKNOWN_READ_FAILURE
;
118 case 'E': /* PROTOCOL ERROR or END */
120 if (buffer
[1] == 'N')
121 return MEMCACHED_END
;
122 else if (buffer
[1] == 'R')
123 return MEMCACHED_PROTOCOL_ERROR
;
125 return MEMCACHED_UNKNOWN_READ_FAILURE
;
127 case 'C': /* CLIENT ERROR */
128 return MEMCACHED_CLIENT_ERROR
;
130 return MEMCACHED_UNKNOWN_READ_FAILURE
;
134 return MEMCACHED_SUCCESS
;
137 char *memcached_result_value(memcached_result_st
*ptr
)
139 memcached_string_st
*sptr
= &ptr
->value
;
140 return memcached_string_value(sptr
);
143 size_t memcached_result_length(memcached_result_st
*ptr
)
145 memcached_string_st
*sptr
= &ptr
->value
;
146 return memcached_string_length(sptr
);