+
+memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result)
+{
+ uint64_t numeric_value;
+
+ return memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value);
+}
+
+memcached_return_t memcached_read_one_response(memcached_server_write_instance_st ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result,
+ uint64_t& numeric_value)
+{
+ memcached_server_response_decrement(ptr);
+
+ if (result == NULL)
+ {
+ memcached_st *root= (memcached_st *)ptr->root;
+ result = &root->result;
+ }
+
+ memcached_return_t rc;
+ if (ptr->root->flags.binary_protocol)
+ {
+ rc= binary_read_one_response(ptr, buffer, buffer_length, result);
+ }
+ else
+ {
+ rc= textual_read_one_response(ptr, buffer, buffer_length, result, numeric_value);
+ }
+
+ if (rc == MEMCACHED_UNKNOWN_READ_FAILURE or
+ rc == MEMCACHED_READ_FAILURE or
+ rc == MEMCACHED_PROTOCOL_ERROR or
+ rc == MEMCACHED_CLIENT_ERROR or
+ rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE)
+ {
+ memcached_io_reset(ptr);
+ }
+
+ return rc;
+}
+
+memcached_return_t memcached_response(memcached_server_write_instance_st ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result)
+{
+ uint64_t numeric_value;
+
+ return memcached_response(ptr, buffer, buffer_length, result, numeric_value);
+}
+
+memcached_return_t memcached_response(memcached_server_write_instance_st ptr,
+ char *buffer, size_t buffer_length,
+ memcached_result_st *result,
+ uint64_t& numeric_value)
+{
+ /* We may have old commands in the buffer not set, first purge */
+ if ((ptr->root->flags.no_block) && (memcached_is_processing_input(ptr->root) == false))
+ {
+ (void)memcached_io_write(ptr, NULL, 0, true);
+ }
+
+ /*
+ * The previous implementation purged all pending requests and just
+ * returned the last one. Purge all pending messages to ensure backwards
+ * compatibility.
+ */
+ if (ptr->root->flags.binary_protocol == false)
+ {
+ while (memcached_server_response_count(ptr) > 1)
+ {
+ memcached_return_t rc= memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value);
+
+ if (rc != MEMCACHED_END &&
+ rc != MEMCACHED_STORED &&
+ rc != MEMCACHED_SUCCESS &&
+ rc != MEMCACHED_STAT &&
+ rc != MEMCACHED_DELETED &&
+ rc != MEMCACHED_NOTFOUND &&
+ rc != MEMCACHED_NOTSTORED &&
+ rc != MEMCACHED_DATA_EXISTS)
+ {
+ return rc;
+ }
+ }
+ }
+
+ return memcached_read_one_response(ptr, buffer, buffer_length, result, numeric_value);
+}