#include "Server.hpp"
-#include "Connection.hpp"
+#include "Retry.hpp"
#include "ForkAndExec.hpp"
#include <sys/wait.h>
optional<string> Server::handleArg(vector<char *> &arr, const string &arg, const arg_func_t &next_arg) {
pushArg(arr, arg);
- if (arg == "-p" || arg == "--port") {
+ if (arg == "-U" || arg == "--udp-port") {
+ auto port = next_arg(arg);
+ pushArg(arr, port);
+ pushArg(arr, "-p");
+ pushArg(arr, port);
+ socket_or_port = stoi(port);
+ return port;
+ } else if (arg == "-p" || arg == "--port") {
auto port = next_arg(arg);
pushArg(arr, port);
-// pushArg(arr, "-U");
-// pushArg(arr, port);
socket_or_port = stoi(port);
return port;
} else if (arg == "-s" || arg == "--unix-socket") {
}
Malloced stat(memcached_stat(*memc, nullptr, nullptr));
- if (!*stat || !stat->pid) {
+ if (!*stat || !stat->pid || stat->pid == -1) {
return false;
}
if (stat->pid != pid) {
return true;
}
+bool Server::ensureListening() {
+ return Retry{[this] {
+ again:
+ start();
+ if (!isListening()) {
+ if (tryWait()){
+ goto again;
+ }
+ }
+ return isListening();
+ }}();
+}
+
bool Server::stop() {
if (!pid) {
return true;
bool Server::wait(int flags) {
if (pid && pid == waitpid(pid, &status, flags)) {
- if (drain().length()) {
- cerr << "Ouput of " << *this << ":\n" << output << endl;
+ if (drain().length() && output != "Signal handled: Terminated.\n") {
+ cerr << "Output of " << *this << ":\n";
+
+ istringstream iss{output};
+ string line;
+
+ while (getline(iss, line)) {
+ cerr << " " << line << "\n";
+ }
+
+ if (output.back() != '\n') {
+ cerr << endl;
+ }
output.clear();
}
pid = 0;