Cluster(const Cluster &c) = delete;
Cluster &operator=(const Cluster &c) = delete;
- Cluster(Cluster &&c)
+ Cluster(Cluster &&c) noexcept
: proto{} {
*this = move(c);
};
- Cluster &operator=(Cluster &&c) {
+ Cluster &operator=(Cluster &&c) noexcept {
count = exchange(c.count, 0);
proto = exchange(c.proto, Server{});
cluster = exchange(c.cluster, {});
#include <cerrno>
#include <sys/poll.h>
-#include <fcntl.h>
#include <unistd.h>
+#if !(HAVE_SOCK_NONBLOCK && HAVE_SOCK_CLOEXEC)
+# include <fcntl.h>
+# define SOCK_NONBLOCK O_NONBLOCK
+# define SOCK_CLOEXEC O_CLOEXEC
+#endif
+
static inline int socket_ex(int af, int so, int pf, int fl) {
#if HAVE_SOCK_NONBLOCK && HAVE_SOCK_CLOEXEC
return socket(af, so | fl, pf);
#else
-# define SOCK_NONBLOCK O_NONBLOCK
-# define SOCK_CLOEXEC O_CLOEXEC
auto sock = socket(af, so, pf);
if (0 <= sock) {
if (0 > fcntl(sock, F_SETFL, fl | fcntl(sock, F_GETFL))) {
string Connection::error(const initializer_list<string> &args) {
stringstream ss;
- for (auto &arg : args) {
+ for (const auto &arg : args) {
ss << arg;
}
UNIX = sizeof(sockaddr_un),
INET = sizeof(sockaddr_in),
INET6 = sizeof(sockaddr_in6)
- } size;
+ } size = NONE;
bool connected{false};
static string error(const initializer_list<string> &args);
#include "ForkAndExec.hpp"
-#include <cerrno>
#include <cstdio>
#include <fcntl.h>
}
MemcachedCluster::~MemcachedCluster() {
- if (memcmp(&memc, &empty_memc, sizeof(memc))) {
+ if (!!memcmp(&memc, &empty_memc, sizeof(memc))) {
memcached_free(&memc);
}
}
init();
}
-MemcachedCluster::MemcachedCluster(MemcachedCluster &&mc)
+MemcachedCluster::MemcachedCluster(MemcachedCluster &&mc) noexcept
: cluster{Server{}}
{
*this = move(mc);
}
-MemcachedCluster &MemcachedCluster::operator=(MemcachedCluster &&mc) {
+MemcachedCluster &MemcachedCluster::operator=(MemcachedCluster &&mc) noexcept {
cluster = move(mc.cluster);
memcached_clone(&memc, &mc.memc);
returns = ReturnMatcher{&memc};
MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, memcached_server_count(&memc) - 1));
}
-void MemcachedCluster::killOneServer() {
+void MemcachedCluster::killOneServer() const {
const auto &servers = cluster.getServers();
const auto &victim = servers[random_num(0UL, servers.size() - 1)];
::kill(victim.getPid(), SIGKILL);
MemcachedCluster(const MemcachedCluster &) = delete;
MemcachedCluster &operator=(const MemcachedCluster &) = delete;
- MemcachedCluster(MemcachedCluster &&mc);
- MemcachedCluster &operator=(MemcachedCluster &&mc);
+ MemcachedCluster(MemcachedCluster &&mc) noexcept;
+ MemcachedCluster &operator=(MemcachedCluster &&mc) noexcept;
void enableBinaryProto(bool enable = true);
void enableBuffering(bool enable = true);
void enableReplication();
- void enableUdp(bool enable = true);
void flush();
static MemcachedCluster mixed();
static MemcachedCluster sasl();
#endif
- void killOneServer();
+ void killOneServer() const;
private:
behaviors_t to_set;
return true;
}
this_thread::sleep_for(dur);
- dur *= 1.2;
+ dur += dur/10;
}
return false;
#include "ReturnMatcher.hpp"
-ReturnMatcher &ReturnMatcher::operator=(ReturnMatcher &&rm) {
- memc = exchange(rm.memc, nullptr);
- expected = rm.expected;
- return *this;
-}
-
bool ReturnMatcher::match(const memcached_return_t &arg) const {
return arg == expected;
}
+ "\n actual: " + memcached_last_error_message(memc);
}
-ReturnMatcher::ReturnMatcher(ReturnMatcher &&rm) {
- *this = move(rm);
-}
ReturnMatcher(const ReturnMatcher &) = default;
- ReturnMatcher(ReturnMatcher &&rm);
- ReturnMatcher &operator=(ReturnMatcher &&rm);
-
bool match(const memcached_return_t &arg) const override;
ReturnMatcher success();
ReturnMatcher operator()(memcached_return_t expected_);
Server(const Server &s);
Server &operator=(const Server &s);
- Server(Server &&s) { *this = move(s); };
- Server &operator=(Server &&s) {
+ Server(Server &&s) noexcept {
+ *this = move(s);
+ };
+ Server &operator=(Server &&s) noexcept {
binary = exchange(s.binary, "false");
args = exchange(s.args, {});
pid = exchange(s.pid, 0);
optional<string> handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg);
};
-inline ostream &operator<<(ostream &out, const socket_or_port_t sop) {
+inline ostream &operator<<(ostream &out, const socket_or_port_t &sop) {
if (holds_alternative<string>(sop)) {
out << get<string>(sop);
} else {
#include "Shell.hpp"
#include <cstdlib>
-#include <unistd.h>
bool Shell::run(const string &command_, string &output) {
auto command = prepareCommand(command_);
}
}
-Shell::Shell(const string &prefix_, bool redirect_stderr)
-: prefix{prefix_}
+Shell::Shell(string prefix_, bool redirect_stderr)
+: prefix{move(prefix_)}
, redirect{redirect_stderr}
{
if (!system(nullptr)) {
class Shell {
public:
explicit Shell(bool redirect_stderr = true);
- explicit Shell(const string &prefix, bool redirect_stderr = true);
+ explicit Shell(string prefix, bool redirect_stderr = true);
bool run(const string &command, string &output);
bool run(const string &command);
#include "common.hpp"
-#include "Connection.hpp"
#include <cstdlib>
close(fd);
unlink(fn);
}
- int getFd() const { return fd; }
- const char *getFn() const { return fn; }
+ [[nodiscard]] int getFd() const { return fd; }
+ [[nodiscard]] const char *getFn() const { return fn; }
bool put(const char *buf, size_t len) const {
return static_cast<ssize_t>(len) == write(fd, buf, len);
}
#include <unistd.h> // getpid()
unsigned random_port() {
- retry:
- auto port = random_num(5000, 32000);
- Connection conn(port);
-
- if (!conn.open()) {
- return port;
- }
- if (!conn.isOpen()) {
- return port;
- }
- goto retry;
+ do {
+ auto port = random_num(5000, 32000);
+ Connection conn(port);
+
+ if (!conn.open()) {
+ return port;
+ }
+ if (!conn.isOpen()) {
+ return port;
+ }
+ } while(true);
}
string random_port_string(const string &) {