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_server_st
*ptr
,
12 char *buffer
, size_t buffer_length
,
13 memcached_result_st
*result
)
18 unsigned int max_messages
;
23 /* We may have old commands in the buffer not set, first purge */
24 if (ptr
->root
->flags
& MEM_NO_BLOCK
)
25 (void)memcached_io_write(ptr
, NULL
, 0, 1);
27 max_messages
= memcached_server_response_count(ptr
);
28 for (x
= 0; x
< max_messages
; x
++)
30 size_t total_length
= 0;
35 unsigned int read_length
;
37 read_length
= memcached_io_read(ptr
, buffer_ptr
, 1);
40 return MEMCACHED_UNKNOWN_READ_FAILURE
;
42 if (*buffer_ptr
== '\n')
48 WATCHPOINT_ASSERT(total_length
<= buffer_length
);
50 if (total_length
>= buffer_length
)
51 return MEMCACHED_PROTOCOL_ERROR
;
56 memcached_server_response_decrement(ptr
);
61 case 'V': /* VALUE || VERSION */
62 if (buffer
[1] == 'A') /* VALUE */
66 /* We add back in one because we will need to search for END */
67 memcached_server_response_increment(ptr
);
69 rc
= value_fetch(ptr
, buffer
, result
);
71 rc
= value_fetch(ptr
, buffer
, &ptr
->root
->result
);
75 else if (buffer
[1] == 'E') /* VERSION */
77 return MEMCACHED_SUCCESS
;
81 WATCHPOINT_STRING(buffer
);
83 return MEMCACHED_UNKNOWN_READ_FAILURE
;
86 return MEMCACHED_SUCCESS
;
87 case 'S': /* STORED STATS SERVER_ERROR */
89 if (buffer
[2] == 'A') /* STORED STATS */
91 memcached_server_response_increment(ptr
);
92 return MEMCACHED_STAT
;
94 else if (buffer
[1] == 'E')
95 return MEMCACHED_SERVER_ERROR
;
96 else if (buffer
[1] == 'T')
97 return MEMCACHED_STORED
;
100 WATCHPOINT_STRING(buffer
);
101 WATCHPOINT_ASSERT(0);
102 return MEMCACHED_UNKNOWN_READ_FAILURE
;
105 case 'D': /* DELETED */
106 return MEMCACHED_DELETED
;
107 case 'N': /* NOT_FOUND */
109 if (buffer
[4] == 'F')
110 return MEMCACHED_NOTFOUND
;
111 else if (buffer
[4] == 'S')
112 return MEMCACHED_NOTSTORED
;
114 return MEMCACHED_UNKNOWN_READ_FAILURE
;
116 case 'E': /* PROTOCOL ERROR or END */
118 if (buffer
[1] == 'N')
119 return MEMCACHED_END
;
120 else if (buffer
[1] == 'R')
121 return MEMCACHED_PROTOCOL_ERROR
;
123 return MEMCACHED_UNKNOWN_READ_FAILURE
;
125 case 'C': /* CLIENT ERROR */
126 return MEMCACHED_CLIENT_ERROR
;
128 return MEMCACHED_UNKNOWN_READ_FAILURE
;
132 return MEMCACHED_SUCCESS
;
135 char *memcached_result_value(memcached_result_st
*ptr
)
137 memcached_string_st
*sptr
= &ptr
->value
;
138 return memcached_string_value(sptr
);
141 size_t memcached_result_length(memcached_result_st
*ptr
)
143 memcached_string_st
*sptr
= &ptr
->value
;
144 return memcached_string_length(sptr
);