+
+memcached_result_st *memcached_fetch_result(memcached_st *ptr,
+ memcached_result_st *result,
+ memcached_return *error)
+{
+ if (result == NULL)
+ result= memcached_result_create(ptr, NULL);
+
+ WATCHPOINT_ASSERT(result->value.is_allocated != MEMCACHED_USED);
+
+ while (ptr->cursor_server < ptr->number_of_hosts)
+ {
+ if (!ptr->hosts[ptr->cursor_server].cursor_active)
+ {
+ ptr->cursor_server++;
+ continue;
+ }
+
+ result->cas= 0; /* We do this so we do not send in any junk */
+ *error= memcached_value_fetch(ptr, result->key, &result->key_length,
+ &result->value,
+ &result->flags,
+ &result->cas,
+ 1, ptr->cursor_server);
+
+ if (*error == MEMCACHED_NOTFOUND)
+ {
+ ptr->hosts[ptr->cursor_server].cursor_active = 0;
+ ptr->cursor_server++;
+ }
+ else if (*error == MEMCACHED_END && memcached_string_length((memcached_string_st *)(&result->value)) == 0)
+ {
+ break;
+ }
+ else if (*error == MEMCACHED_END)
+ {
+ WATCHPOINT_ASSERT(0); /* If this happens we have somehow messed up the fetch */
+ break;
+ }
+ else if (*error != MEMCACHED_SUCCESS)
+ {
+ break;
+ }
+ else
+ {
+ return result;
+ }
+ }
+
+ /* An error has occurred */
+ if (result->is_allocated == MEMCACHED_ALLOCATED)
+ memcached_result_free(result);
+ else
+ memcached_string_reset(&result->value);
+
+ return NULL;
+}