+ to_write= (ptr->flags & MEM_BUFFER_REQUESTS) ? 0 : 1;
+
+ do
+ {
+ rc[replicas]= memcached_do(&ptr->hosts[server_key], buffer, send_length, to_write);
+ if (rc[replicas] != MEMCACHED_SUCCESS)
+ goto error;
+
+ if ((ptr->flags & MEM_BUFFER_REQUESTS))
+ {
+ rc[replicas]= MEMCACHED_BUFFERED;
+ }
+ else
+ {
+ rc[replicas]= memcached_response(&ptr->hosts[server_key], buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);
+ if (rc[replicas] == MEMCACHED_DELETED)
+ rc[replicas]= MEMCACHED_SUCCESS;
+ }
+
+ /* On error we just jump to the next potential server */
+error:
+ if (replicas > 1 && ptr->distribution == MEMCACHED_DISTRIBUTION_CONSISTENT)
+ {
+ if (server_key == (ptr->number_of_hosts - 1))
+ server_key= 0;
+ else
+ server_key++;
+ }
+ } while ((++replicas) < ptr->number_of_replicas);
+
+ /* As long as one object gets stored, we count this as a success */
+ while (replicas--)
+ {
+ if (rc[replicas] == MEMCACHED_DELETED)
+ return MEMCACHED_SUCCESS;
+ else if (rc[replicas] == MEMCACHED_DELETED)
+ rc[replicas]= MEMCACHED_BUFFERED;