Credentials credentials;
};
+ void prepare(bool activation);
+
typedef std::list<std::shared_ptr<Connection>> ConnectionRegistry;
typedef std::function<void(const std::shared_ptr<Connection>& connection)> CallbackDispatcher;
std::mutex methodRegistryLock;
static thread_local ProcessingContext processingContext;
+ std::unique_ptr<Socket> socket;
};
template<typename Type, typename... Args>
if (pollFd == -1) {
throw Exception(GetSystemErrorMessage());
}
+
+ prepare();
}
Mainloop::~Mainloop()
bool done = false;
stopped = false;
- prepare();
-
while (!stopped && !done) {
done = !dispatch(timeout);
}
{
}
-void Service::start(bool activation, int timeout)
+void Service::prepare(bool activation)
{
- Socket socket(Socket::create(address, activation));
-
+ socket.reset(new Socket(Socket::create(address, activation)));
auto accept = [&](int fd, runtime::Mainloop::Event event) {
- onNewConnection(std::make_shared<Connection>(socket.accept()));
+ onNewConnection(std::make_shared<Connection>(socket->accept()));
};
- mainloop.addEventSource(socket.getFd(),
+ mainloop.addEventSource(socket->getFd(),
EPOLLIN | EPOLLHUP | EPOLLRDHUP,
accept);
+}
+void Service::start(bool activation, int timeout)
+{
+ if (socket == nullptr) {
+ prepare(activation);
+ }
mainloop.run(timeout);
}