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
;
22 /* UDP at the moment is odd...*/
23 if (ptr
->type
== MEMCACHED_CONNECTION_UDP
)
28 return MEMCACHED_SUCCESS
;
30 read_length
= memcached_io_read(ptr
, buffer
, 8);
33 /* We may have old commands in the buffer not set, first purge */
34 if (ptr
->root
->flags
& MEM_NO_BLOCK
)
35 (void)memcached_io_write(ptr
, NULL
, 0, 1);
37 max_messages
= memcached_server_response_count(ptr
);
38 for (x
= 0; x
< max_messages
; x
++)
40 size_t total_length
= 0;
48 read_length
= memcached_io_read(ptr
, buffer_ptr
, 1);
49 WATCHPOINT_ASSERT(isgraph(*buffer_ptr
) || isspace(*buffer_ptr
));
53 memcached_io_reset(ptr
);
54 return MEMCACHED_UNKNOWN_READ_FAILURE
;
57 if (*buffer_ptr
== '\n')
63 WATCHPOINT_ASSERT(total_length
<= buffer_length
);
65 if (total_length
>= buffer_length
)
67 memcached_io_reset(ptr
);
68 return MEMCACHED_PROTOCOL_ERROR
;
74 memcached_server_response_decrement(ptr
);
79 case 'V': /* VALUE || VERSION */
80 if (buffer
[1] == 'A') /* VALUE */
84 /* We add back in one because we will need to search for END */
85 memcached_server_response_increment(ptr
);
87 rc
= value_fetch(ptr
, buffer
, result
);
89 rc
= value_fetch(ptr
, buffer
, &ptr
->root
->result
);
93 else if (buffer
[1] == 'E') /* VERSION */
95 return MEMCACHED_SUCCESS
;
99 WATCHPOINT_STRING(buffer
);
100 WATCHPOINT_ASSERT(0);
101 memcached_io_reset(ptr
);
102 return MEMCACHED_UNKNOWN_READ_FAILURE
;
105 return MEMCACHED_SUCCESS
;
106 case 'S': /* STORED STATS SERVER_ERROR */
108 if (buffer
[2] == 'A') /* STORED STATS */
110 memcached_server_response_increment(ptr
);
111 return MEMCACHED_STAT
;
113 else if (buffer
[1] == 'E')
114 return MEMCACHED_SERVER_ERROR
;
115 else if (buffer
[1] == 'T')
116 return MEMCACHED_STORED
;
119 WATCHPOINT_STRING(buffer
);
120 WATCHPOINT_ASSERT(0);
121 memcached_io_reset(ptr
);
122 return MEMCACHED_UNKNOWN_READ_FAILURE
;
125 case 'D': /* DELETED */
126 return MEMCACHED_DELETED
;
127 case 'N': /* NOT_FOUND */
129 if (buffer
[4] == 'F')
130 return MEMCACHED_NOTFOUND
;
131 else if (buffer
[4] == 'S')
132 return MEMCACHED_NOTSTORED
;
135 memcached_io_reset(ptr
);
136 return MEMCACHED_UNKNOWN_READ_FAILURE
;
139 case 'E': /* PROTOCOL ERROR or END */
141 if (buffer
[1] == 'N')
142 return MEMCACHED_END
;
143 else if (buffer
[1] == 'R')
145 memcached_io_reset(ptr
);
146 return MEMCACHED_PROTOCOL_ERROR
;
150 memcached_io_reset(ptr
);
151 return MEMCACHED_UNKNOWN_READ_FAILURE
;
154 case 'C': /* CLIENT ERROR */
155 memcached_io_reset(ptr
);
156 return MEMCACHED_CLIENT_ERROR
;
158 memcached_io_reset(ptr
);
159 return MEMCACHED_UNKNOWN_READ_FAILURE
;
163 return MEMCACHED_SUCCESS
;
166 char *memcached_result_value(memcached_result_st
*ptr
)
168 memcached_string_st
*sptr
= &ptr
->value
;
169 return memcached_string_value(sptr
);
172 size_t memcached_result_length(memcached_result_st
*ptr
)
174 memcached_string_st
*sptr
= &ptr
->value
;
175 return memcached_string_length(sptr
);