- if (!memcmp(buffer, "ERROR\r\n", MEMCACHED_DEFAULT_COMMAND_SIZE))
- {
- *value= 0;
- rc= MEMCACHED_PROTOCOL_ERROR;
- }
- else if (!memcmp(buffer, "NOT_FOUND\r\n", MEMCACHED_DEFAULT_COMMAND_SIZE))
- {
- *value= 0;
- rc= MEMCACHED_NOTFOUND;
- }
- else
+ /*
+ So why recheck responce? Because the protocol is brain dead :)
+ The number returned might end up equaling one of the string
+ values. Less chance of a mistake with strncmp() so we will
+ use it. We still called memcached_response() though since it
+ worked its magic for non-blocking IO.
+ */
+ if (!strncmp(buffer, "ERROR\r\n", 7))
+ {
+ *value= 0;
+ rc[replicas]= MEMCACHED_PROTOCOL_ERROR;
+ }
+ else if (!strncmp(buffer, "NOT_FOUND\r\n", 11))
+ {
+ *value= 0;
+ rc[replicas]= MEMCACHED_NOTFOUND;
+ }
+ else
+ {
+ *value= (uint64_t)strtoll(buffer, (char **)NULL, 10);
+ 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--)