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;
37 read_length
= memcached_io_read(ptr
, buffer_ptr
, 1);
38 WATCHPOINT_ASSERT(isgraph(*buffer_ptr
) || isspace(*buffer_ptr
));
41 return MEMCACHED_UNKNOWN_READ_FAILURE
;
43 if (*buffer_ptr
== '\n')
49 WATCHPOINT_ASSERT(total_length
<= buffer_length
);
51 if (total_length
>= buffer_length
)
52 return MEMCACHED_PROTOCOL_ERROR
;
57 memcached_server_response_decrement(ptr
);
62 case 'V': /* VALUE || VERSION */
63 if (buffer
[1] == 'A') /* VALUE */
67 /* We add back in one because we will need to search for END */
68 memcached_server_response_increment(ptr
);
70 rc
= value_fetch(ptr
, buffer
, result
);
72 rc
= value_fetch(ptr
, buffer
, &ptr
->root
->result
);
76 else if (buffer
[1] == 'E') /* VERSION */
78 return MEMCACHED_SUCCESS
;
82 WATCHPOINT_STRING(buffer
);
84 return MEMCACHED_UNKNOWN_READ_FAILURE
;
87 return MEMCACHED_SUCCESS
;
88 case 'S': /* STORED STATS SERVER_ERROR */
90 if (buffer
[2] == 'A') /* STORED STATS */
92 memcached_server_response_increment(ptr
);
93 return MEMCACHED_STAT
;
95 else if (buffer
[1] == 'E')
96 return MEMCACHED_SERVER_ERROR
;
97 else if (buffer
[1] == 'T')
98 return MEMCACHED_STORED
;
101 WATCHPOINT_STRING(buffer
);
102 WATCHPOINT_ASSERT(0);
103 return MEMCACHED_UNKNOWN_READ_FAILURE
;
106 case 'D': /* DELETED */
107 return MEMCACHED_DELETED
;
108 case 'N': /* NOT_FOUND */
110 if (buffer
[4] == 'F')
111 return MEMCACHED_NOTFOUND
;
112 else if (buffer
[4] == 'S')
113 return MEMCACHED_NOTSTORED
;
115 return MEMCACHED_UNKNOWN_READ_FAILURE
;
117 case 'E': /* PROTOCOL ERROR or END */
119 if (buffer
[1] == 'N')
120 return MEMCACHED_END
;
121 else if (buffer
[1] == 'R')
122 return MEMCACHED_PROTOCOL_ERROR
;
124 return MEMCACHED_UNKNOWN_READ_FAILURE
;
126 case 'C': /* CLIENT ERROR */
127 return MEMCACHED_CLIENT_ERROR
;
129 return MEMCACHED_UNKNOWN_READ_FAILURE
;
133 return MEMCACHED_SUCCESS
;
136 char *memcached_result_value(memcached_result_st
*ptr
)
138 memcached_string_st
*sptr
= &ptr
->value
;
139 return memcached_string_value(sptr
);
142 size_t memcached_result_length(memcached_result_st
*ptr
)
144 memcached_string_st
*sptr
= &ptr
->value
;
145 return memcached_string_length(sptr
);