5 void Cluster::reset() {
8 for (int i
= 0; i
< count
; ++i
) {
9 cluster
.push_back(proto
);
13 bool Cluster::start() {
16 for (auto &server
: cluster
) {
17 auto pid
= server
.start();
18 if (started
&= pid
.has_value()) {
26 void Cluster::stop() {
27 for (auto &server
: cluster
) {
32 bool Cluster::isStopped() {
33 for (auto &server
: cluster
) {
34 if (server
.getPid() && !server
.tryWait()) {
41 bool Cluster::isListening(int max_timeout
) {
42 vector
<WaitForConn::conn_t
> conns
;
44 for (auto &server
: cluster
) {
45 auto conn
= server
.createSocket();
49 conns
.emplace_back(conn
.value());
52 WaitForConn wait_for_conn
{
54 Poll
{POLLOUT
, 2, max_timeout
}
56 return wait_for_conn();
59 void Cluster::wait() {
62 while (!isStopped()) {
63 if (waitid(P_ALL
, 0, &inf
, WEXITED
| WNOWAIT
)) {
64 perror("Cluster::wait waitid()");
68 if (pids
[inf
.si_pid
]) {
69 pids
[inf
.si_pid
]->wait();