A simple server illustrating several customisations
#include <chrono>
#include <cstdlib>
namespace
{
auto connection(int fd) -> std::string
{
char connect_string[64] = {0};
sprintf(connect_string, "fd://%d", dup(fd));
return connect_string;
}
{
static const char* const launch_child_opt = "launch-client";
static const char* const launch_client_descr = "system() command to launch client";
{
if (options->is_set(launch_child_opt))
{
auto const value = options->get<std::string>(launch_child_opt);
for (
auto i =
begin(value); i !=
end(value); )
{
auto const j = find(i,
end(value),
'&');
auto const cmd =
"MIR_SOCKET=" + connection(server.
open_client_socket()) +
" " + std::string{i, j} +
"&";
auto ignore = std::system(cmd.c_str());
(void)(ignore);
if ((i = j) !=
end(value)) ++i;
}
}
});
}
{
static const char* const timeout_opt = "timeout";
static const char* const timeout_descr = "Seconds to run before exiting";
{
if (options->is_set(timeout_opt))
{
static auto const exit_action = server.
the_main_loop()->create_alarm([&server] { server.
stop(); });
exit_action->reschedule_in(std::chrono::seconds(options->get<int>(timeout_opt)));
}
});
}
}
int main(
int argc,
char const* argv[])
try
{
add_launcher_option_to(server);
add_timeout_option_to(server);
{
return EXIT_FAILURE;
}
}
catch (...)
{
return EXIT_FAILURE;
}
Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016