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
));
52 return MEMCACHED_UNKNOWN_READ_FAILURE
;
54 if (*buffer_ptr
== '\n')
60 WATCHPOINT_ASSERT(total_length
<= buffer_length
);
62 if (total_length
>= buffer_length
)
63 return MEMCACHED_PROTOCOL_ERROR
;
68 memcached_server_response_decrement(ptr
);
73 case 'V': /* VALUE || VERSION */
74 if (buffer
[1] == 'A') /* VALUE */
78 /* We add back in one because we will need to search for END */
79 memcached_server_response_increment(ptr
);
81 rc
= value_fetch(ptr
, buffer
, result
);
83 rc
= value_fetch(ptr
, buffer
, &ptr
->root
->result
);
87 else if (buffer
[1] == 'E') /* VERSION */
89 return MEMCACHED_SUCCESS
;
93 WATCHPOINT_STRING(buffer
);
95 return MEMCACHED_UNKNOWN_READ_FAILURE
;
98 return MEMCACHED_SUCCESS
;
99 case 'S': /* STORED STATS SERVER_ERROR */
101 if (buffer
[2] == 'A') /* STORED STATS */
103 memcached_server_response_increment(ptr
);
104 return MEMCACHED_STAT
;
106 else if (buffer
[1] == 'E')
107 return MEMCACHED_SERVER_ERROR
;
108 else if (buffer
[1] == 'T')
109 return MEMCACHED_STORED
;
112 WATCHPOINT_STRING(buffer
);
113 WATCHPOINT_ASSERT(0);
114 return MEMCACHED_UNKNOWN_READ_FAILURE
;
117 case 'D': /* DELETED */
118 return MEMCACHED_DELETED
;
119 case 'N': /* NOT_FOUND */
121 if (buffer
[4] == 'F')
122 return MEMCACHED_NOTFOUND
;
123 else if (buffer
[4] == 'S')
124 return MEMCACHED_NOTSTORED
;
126 return MEMCACHED_UNKNOWN_READ_FAILURE
;
128 case 'E': /* PROTOCOL ERROR or END */
130 if (buffer
[1] == 'N')
131 return MEMCACHED_END
;
132 else if (buffer
[1] == 'R')
133 return MEMCACHED_PROTOCOL_ERROR
;
135 return MEMCACHED_UNKNOWN_READ_FAILURE
;
137 case 'C': /* CLIENT ERROR */
138 return MEMCACHED_CLIENT_ERROR
;
140 return MEMCACHED_UNKNOWN_READ_FAILURE
;
144 return MEMCACHED_SUCCESS
;
147 char *memcached_result_value(memcached_result_st
*ptr
)
149 memcached_string_st
*sptr
= &ptr
->value
;
150 return memcached_string_value(sptr
);
153 size_t memcached_result_length(memcached_result_st
*ptr
)
155 memcached_string_st
*sptr
= &ptr
->value
;
156 return memcached_string_length(sptr
);