5 Cluster::Cluster(Server
&&serv
, uint16_t cnt
)
7 , proto
{forward
<Server
>(serv
)}
10 count
= thread::hardware_concurrency()/2 ?: 4;
20 const vector
<Server
> &Cluster::getServers() const {
24 void Cluster::reset() {
27 for (int i
= 0; i
< count
; ++i
) {
28 cluster
.push_back(proto
);
32 bool Cluster::start() {
35 for (auto &server
: cluster
) {
36 auto pid
= server
.start();
37 if (pid
.has_value()) {
47 void Cluster::stop() {
48 for (auto &server
: cluster
) {
49 // no cookies for memcached; TERM is just too slow
50 server
.signal(SIGKILL
);
54 bool Cluster::isStopped() {
55 for (auto &server
: cluster
) {
56 if (server
.getPid() && !server
.tryWait()) {
63 bool Cluster::isListening() {
64 for (auto &server
: cluster
) {
65 if (!server
.isListening()) {
67 auto old_pid
= server
.getPid();
68 if (server
.tryWait()) {
70 auto pid
= server
.start();
71 if (pid
.has_value()) {
75 return server
.isListening();
82 void Cluster::wait() {
85 while (!isStopped()) {
86 if (waitid(P_ALL
, 0, &inf
, WEXITED
| WNOWAIT
)) {
87 perror("Cluster::wait waitid()");
91 auto server
= pids
.find(inf
.si_pid
);
92 if (server
!= pids
.end()) {
93 server
->second
->wait();