X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=util%2Finstance.cc;h=e96f414f72e6280ba899414496b81ce376c3c5ac;hb=68ad48824e7162a490cce315756c5fa3f98d3e31;hp=19d01fcf913c4d5d805d9e7e6eded819521ffd9e;hpb=9169cee9ec0f231b3117a0d5a7840d2067f29610;p=m6w6%2Flibmemcached 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 -#include #include #include +#include #include +#include #include #include -#include + +#ifdef HAVE_UNISTD_H +#include +#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(read_length)); total_read+= static_cast(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;