diff options
author | Brian Aker <brian@tangent.org> | 2012-02-16 18:39:27 -0800 |
---|---|---|
committer | Brian Aker <brian@tangent.org> | 2012-02-16 18:39:27 -0800 |
commit | 751e342e158ae65052ce098ccd64aa54e39312db (patch) | |
tree | 8b74445ef834c05606f0222a31ffa67fbdb884bc /util | |
parent | fabf488ffa687540145ca8973ceb3fb0147a858b (diff) | |
download | libmemcached-751e342e158ae65052ce098ccd64aa54e39312db.tar.gz |
Update libtest/associated tests.
Diffstat (limited to 'util')
-rw-r--r-- | util/daemon.cc | 2 | ||||
-rw-r--r-- | util/instance.cc | 29 | ||||
-rw-r--r-- | util/operation.cc | 2 | ||||
-rw-r--r-- | util/signal.hpp | 4 | ||||
-rw-r--r-- | util/string.hpp | 2 |
5 files changed, 33 insertions, 6 deletions
diff --git a/util/daemon.cc b/util/daemon.cc index 3b129d18..68393297 100644 --- a/util/daemon.cc +++ b/util/daemon.cc @@ -77,7 +77,7 @@ bool daemon_is_ready(bool close_io) return false; } - if (not close_io) + if (close_io == false) { return true;; } diff --git a/util/instance.cc b/util/instance.cc index 19d01fcf..e96f414f 100644 --- a/util/instance.cc +++ b/util/instance.cc @@ -41,13 +41,17 @@ #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 { @@ -213,20 +217,31 @@ bool Instance::run() 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 +291,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 +310,10 @@ void Instance::close_socket() void Instance::free_addrinfo() { - if (not _addrinfo) + if (_addrinfo == NULL) + { return; + } freeaddrinfo(_addrinfo); _addrinfo= NULL; diff --git a/util/operation.cc b/util/operation.cc index ad19e2b7..def31a6b 100644 --- a/util/operation.cc +++ b/util/operation.cc @@ -47,7 +47,9 @@ namespace util { bool Operation::response(std::string &arg) { if (_response.empty()) + { return false; + } if (not memcmp("OK\r\n", &_response[0], 3)) { } diff --git a/util/signal.hpp b/util/signal.hpp index 7573fe65..b15bf0e4 100644 --- a/util/signal.hpp +++ b/util/signal.hpp @@ -26,6 +26,10 @@ #include <pthread.h> #include <semaphore.h> +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif + namespace datadifferential { namespace util { diff --git a/util/string.hpp b/util/string.hpp index 873551e5..9f678698 100644 --- a/util/string.hpp +++ b/util/string.hpp @@ -51,5 +51,7 @@ #define util_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) +#define util_string_make_from_array(__array) (__array), (strlen(__array)) + #define util_array_length(__array) sizeof(__array)/sizeof(&__array) |