Add a request id for each request that hits the wire.
[m6w6/libmemcached] / libmemcached / sasl.cc
index 902ccd872cf77ee7ede0903730a31c6c9bd96f3d..603c5864091a27b143f1d3c1e03b8c214ecc8129 100644 (file)
 
 #if defined(LIBMEMCACHED_WITH_SASL_SUPPORT) && LIBMEMCACHED_WITH_SASL_SUPPORT
 
+#if defined(HAVE_LIBSASL) && HAVE_LIBSASL
 #include <sasl/sasl.h>
+#endif
+
 #include <pthread.h>
 
 void memcached_set_sasl_callbacks(memcached_st *ptr,
@@ -144,7 +147,9 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s
    * as authenticated
  */
   protocol_binary_request_no_extras request= { };
-  request.message.header.request.magic= PROTOCOL_BINARY_REQ;
+
+  initialize_binary_request(ptr, request.message.header);
+
   request.message.header.request.opcode= PROTOCOL_BINARY_CMD_SASL_LIST_MECHS;
 
   if (memcached_io_write(server, request.bytes,
@@ -237,7 +242,7 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s
       { data, len }
     };
 
-    if (memcached_io_writev(server, vector, 3, true) == -1)
+    if (memcached_io_writev(server, vector, 3, true) == false)
     {
       rc= MEMCACHED_WRITE_FAILURE;
       break;
@@ -424,7 +429,7 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const  memcached_st
    * into the list, but if we don't know the ID we don't know how to handle
    * the context...
  */
-  size_t total= 0;
+  ptrdiff_t total= 0;
 
   while (source->sasl.callbacks[total].id != SASL_CB_LIST_END)
   {
@@ -450,7 +455,7 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const  memcached_st
   memcpy(callbacks, source->sasl.callbacks, (total + 1) * sizeof(sasl_callback_t));
 
   /* Now update the context... */
-  for (size_t x= 0; x < total; ++x)
+  for (ptrdiff_t x= 0; x < total; ++x)
   {
     if (callbacks[x].id == SASL_CB_USER || callbacks[x].id == SASL_CB_AUTHNAME)
     {
@@ -459,7 +464,7 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const  memcached_st
       if (callbacks[x].context == NULL)
       {
         /* Failed to allocate memory, clean up previously allocated memory */
-        for (size_t y= 0; y < x; ++y)
+        for (ptrdiff_t y= 0; y < x; ++y)
         {
           libmemcached_free(clone, clone->sasl.callbacks[y].context);
         }
@@ -476,7 +481,7 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const  memcached_st
       if (n == NULL)
       {
         /* Failed to allocate memory, clean up previously allocated memory */
-        for (size_t y= 0; y < x; ++y)
+        for (ptrdiff_t y= 0; y < x; ++y)
         {
           libmemcached_free(clone, clone->sasl.callbacks[y].context);
         }