Updating the get function in the C++ interface.
[awesomized/libmemcached] / libmemcached / memcached_io.c
index 95774865445ced3318f32cb26cea51da29a7809c..69771d71f172c7f421c2aea792b3af1e9d2e7cdf 100644 (file)
@@ -23,9 +23,9 @@ static memcached_return io_wait(memcached_server_st *ptr,
   int error;
 
   if (read_or_write == MEM_WRITE) /* write */
-    flags= POLLOUT |  POLLERR;
+    flags= POLLOUT;
   else
-    flags= POLLIN | POLLERR;
+    flags= POLLIN;
 
   memset(&fds, 0, sizeof(struct pollfd));
   fds[0].fd= ptr->fd;
@@ -227,8 +227,10 @@ ssize_t memcached_io_write(memcached_server_st *ptr,
         return -1;
 
       /* If io_flush calls memcached_purge, sent_length may be 0 */
-      if (sent_length != 0)
-        WATCHPOINT_ASSERT(sent_length == buffer_end);
+      unlikely (sent_length != 0)
+      {
+        WATCHPOINT_ASSERT(sent_length == (ssize_t)buffer_end);
+      }
     }
   }
 
@@ -255,7 +257,7 @@ memcached_return memcached_io_close(memcached_server_st *ptr)
   {
     r= shutdown(ptr->fd, SHUT_RDWR);
 
-#ifdef HAVE_DEBUG
+#ifdef DEBUG
     if (r && errno != ENOTCONN)
     {
       WATCHPOINT_NUMBER(ptr->fd);
@@ -266,7 +268,7 @@ memcached_return memcached_io_close(memcached_server_st *ptr)
   }
 
   r= close(ptr->fd);
-#ifdef HAVE_DEBUG
+#ifdef DEBUG
   if (r != 0)
     WATCHPOINT_ERRNO(errno);
 #endif
@@ -278,33 +280,35 @@ memcached_server_st *memcached_io_get_readable_server(memcached_st *memc)
 {
 #define MAX_SERVERS_TO_POLL 100
   struct pollfd fds[MAX_SERVERS_TO_POLL];
-  int index= 0;
+  unsigned int host_index= 0;
 
-  for (int x= 0; x< memc->number_of_hosts && index < MAX_SERVERS_TO_POLL; ++x)
+  for (unsigned int x= 0;
+       x< memc->number_of_hosts && host_index < MAX_SERVERS_TO_POLL;
+       ++x)
   {
     if (memc->hosts[x].read_buffer_length > 0) /* I have data in the buffer */
       return &memc->hosts[x];
 
     if (memcached_server_response_count(&memc->hosts[x]) > 0)
     {
-      fds[index].events = POLLIN;
-      fds[index].revents = 0;
-      fds[index].fd = memc->hosts[x].fd;
-      ++index;
+      fds[host_index].events = POLLIN;
+      fds[host_index].revents = 0;
+      fds[host_index].fd = memc->hosts[x].fd;
+      ++host_index;
     }
   }
 
-  if (index < 2)
+  if (host_index < 2)
   {
     /* We have 0 or 1 server with pending events.. */
-    for (int x= 0; x< memc->number_of_hosts; ++x)
+    for (unsigned int x= 0; x< memc->number_of_hosts; ++x)
       if (memcached_server_response_count(&memc->hosts[x]) > 0)
         return &memc->hosts[x];
 
     return NULL;
   }
 
-  int err= poll(fds, index, memc->poll_timeout);
+  int err= poll(fds, host_index, memc->poll_timeout);
   switch (err) {
   case -1:
     memc->cached_errno = errno;
@@ -312,9 +316,9 @@ memcached_server_st *memcached_io_get_readable_server(memcached_st *memc)
   case 0:
     break;
   default:
-    for (int x= 0; x < index; ++x)
+    for (unsigned int x= 0; x < host_index; ++x)
       if (fds[x].revents & POLLIN)
-        for (int y= 0; y < memc->number_of_hosts; ++y)
+        for (unsigned int y= 0; y < memc->number_of_hosts; ++y)
           if (memc->hosts[y].fd == fds[x].fd)
             return &memc->hosts[y];
   }
@@ -356,7 +360,7 @@ static ssize_t io_flush(memcached_server_st *ptr,
     return 0;
 
   /* Looking for memory overflows */
-#if defined(HAVE_DEBUG)
+#if defined(DEBUG)
   if (write_length == MEMCACHED_MAX_BUFFER)
     WATCHPOINT_ASSERT(ptr->write_buffer == local_write_ptr);
   WATCHPOINT_ASSERT((ptr->write_buffer + MEMCACHED_MAX_BUFFER) >= (local_write_ptr + write_length));
@@ -397,7 +401,8 @@ static ssize_t io_flush(memcached_server_st *ptr,
       }
     }
 
-    if (ptr->type == MEMCACHED_CONNECTION_UDP && sent_length != write_length)
+    if (ptr->type == MEMCACHED_CONNECTION_UDP &&
+        (size_t)sent_length != write_length)
     {
       memcached_quit_server(ptr, 1);
       return -1;
@@ -462,7 +467,7 @@ memcached_return memcached_io_readline(memcached_server_st *ptr,
                                        size_t size)
 {
   bool line_complete= false;
-  int total_nr= 0;
+  size_t total_nr= 0;
 
   while (!line_complete)
   {