Crank up alarm value.
[awesomized/libmemcached] / util / instance.cc
index 23c8aec4f5947997d871bf766f70636c00851dca..8b9f5ee94afa5da24dd60f8600868a21c131836a 100644 (file)
 #include "util/instance.hpp"
 
 #include <cstdio>
-#include <sstream>
 #include <iostream>
 #include <netdb.h>
+#include <netinet/in.h>
 #include <poll.h>
+#include <sstream>
 #include <sys/socket.h>
 #include <sys/types.h>
-#include <netinet/in.h>
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
 
 
 namespace datadifferential {
@@ -192,7 +196,7 @@ bool Instance::run()
             switch(errno)
             {
             default:
-              std::cerr << "Failed during send(" << strerror(errno) << ")" << std::endl;
+              std::cerr << "Failed dureng send(" << strerror(errno) << ")" << std::endl;
               break;
             }
           }
@@ -207,26 +211,35 @@ bool Instance::run()
     case READING:
       if (operation->has_response())
       {
-        size_t total_read;
         ssize_t read_length;
 
         do
         {
           char buffer[BUFSIZ];
-          read_length= recv(_sockfd, buffer, sizeof(buffer), 0);
+          read_length= ::recv(_sockfd, buffer, sizeof(buffer), 0);
 
           if (read_length < 0)
           {
             switch(errno)
             {
             default:
-              std::cerr << "Error occured while reading data from " << _host.c_str() << std::endl;
+              _last_error.clear();
+              _last_error+= "Error occured while reading data from ";
+              _last_error+= _host;
               return false;
             }
           }
+          else if (read_length == 0)
+          {
+            _last_error.clear();
+            _last_error+= "Socket was shutdown while reading from ";
+            _last_error+= _host;
+
+            return false;
+          }
 
           operation->push(buffer, static_cast<size_t>(read_length));
-          total_read+= static_cast<size_t>(read_length);
+
         } while (more_to_read());
       } // end has_response
 
@@ -276,7 +289,9 @@ bool Instance::more_to_read() const
 void Instance::close_socket()
 {
   if (_sockfd == INVALID_SOCKET)
+  {
     return;
+  }
 
   /* in case of death shutdown to avoid blocking at close() */
   if (shutdown(_sockfd, SHUT_RDWR) == SOCKET_ERROR && get_socket_errno() != ENOTCONN)
@@ -293,8 +308,10 @@ void Instance::close_socket()
 
 void Instance::free_addrinfo()
 {
-  if (not _addrinfo)
+  if (_addrinfo == NULL)
+  {
     return;
+  }
 
   freeaddrinfo(_addrinfo);
   _addrinfo= NULL;