Cleanup for OSX 9
[awesomized/libmemcached] / clients / execute.cc
index b276954533e1b119375cd3aba183886dfbf30d21..47319778e868b7b51efff6b40dffd9acdae552fa 100644 (file)
@@ -1,4 +1,5 @@
 /* LibMemcached
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
  * Copyright (C) 2006-2009 Brian Aker
  * All rights reserved.
  *
   Return the number of rows set.
 */
 
-#include <config.h>
+#include <mem_config.h>
 #include "clients/execute.h"
 
 unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
 {
-  unsigned int x;
-  unsigned int pairs_sent;
-
-  for (x= 0, pairs_sent= 0; x < number_of; x++)
+  uint32_t count= 0;
+  for (; count < number_of; ++count)
   {
-    memcached_return_t rc= memcached_set(memc, pairs[x].key, pairs[x].key_length,
-                                         pairs[x].value, pairs[x].value_length,
+    memcached_return_t rc= memcached_set(memc, pairs[count].key, pairs[count].key_length,
+                                         pairs[count].value, pairs[count].value_length,
                                          0, 0);
-    if (rc != MEMCACHED_SUCCESS and rc != MEMCACHED_BUFFERED)
+    if (memcached_failed(rc))
     {
-      fprintf(stderr, "%s:%d Failure on insert (%s) of %.*s\n",
-              __FILE__, __LINE__,
+      fprintf(stderr, "%s:%d Failure on %u insert (%s) of %.*s\n",
+              __FILE__, __LINE__, count,
               memcached_last_error_message(memc),
-              (unsigned int)pairs[x].key_length, pairs[x].key);
+              (unsigned int)pairs[count].key_length, pairs[count].key);
       
       // We will try to reconnect and see if that fixes the issue
       memcached_quit(memc);
-    }
-    else
-    {
-      pairs_sent++;
+
+      return count;
     }
   }
 
-  return pairs_sent;
+  return count;
 }
 
 /*
@@ -52,7 +49,6 @@ unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int numbe
 */
 unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int number_of)
 {
-  memcached_return_t rc;
   unsigned int x;
   unsigned int retrieved;
 
@@ -64,10 +60,11 @@ unsigned int execute_get(memcached_st *memc, pairs_st *pairs, unsigned int numbe
 
     unsigned int fetch_key= (unsigned int)((unsigned int)random() % number_of);
 
+    memcached_return_t rc;
     char *value= memcached_get(memc, pairs[fetch_key].key, pairs[fetch_key].key_length,
                                &value_length, &flags, &rc);
 
-    if (rc != MEMCACHED_SUCCESS)
+    if (memcached_failed(rc))
     {
       fprintf(stderr, "%s:%d Failure on read(%s) of %.*s\n",
               __FILE__, __LINE__,