1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 10:24:26 +01:00

automatic shutdown & reconnection

This commit is contained in:
Ralf Ramsauer 2015-10-01 22:57:01 +02:00
parent 6181412d7b
commit 2b620d37e9

View File

@ -28,17 +28,17 @@ namespace po = boost::program_options;
namespace ba = boost::asio; namespace ba = boost::asio;
using ba::ip::tcp; using ba::ip::tcp;
ba::io_service io_service; static ba::io_service io_service;
const static std::string subscriptionCommand = const static std::string subscriptionCommand =
"{ \"command\": \"subscribe\"}"; "{ \"command\": \"subscribe\"}";
// The receive buffer length of the TCP socket // The receive buffer length of the TCP socket
const int constexpr SOCKET_BUFFERLENGTH = 2048; constexpr static int SOCKET_BUFFERLENGTH = 2048;
static volatile bool run = true; static volatile bool run = true;
std::unique_ptr<MainWindow> mainWindow = nullptr; static std::unique_ptr<MainWindow> mainWindow = nullptr;
static void onDoorlockUpdate(const Clientmessage &msg) static void onDoorlockUpdate(const Clientmessage &msg)
{ {
@ -173,9 +173,12 @@ int main(int argc, char** argv)
// In normal operation, it never returns // In normal operation, it never returns
while (run) { while (run) {
doorlock_client(hostname, port); doorlock_client(hostname, port);
l(LogLevel::error, "client aborted, retrying in 5 seconds"); if (run) {
sleep(5); l(LogLevel::error, "client aborted, retrying in 5 seconds");
// Todo: Write message to QT frontend // Todo: Write message to QT frontend
sleep(5);
}
} }
// This will stop the Qapplication // This will stop the Qapplication
@ -186,9 +189,10 @@ int main(int argc, char** argv)
// This routine will never return in normal operation // This routine will never return in normal operation
app.exec(); app.exec();
run = false;
// Stop the IO service // Stop the IO service
io_service.stop(); io_service.stop();
io_service.reset();
clientThread.join(); clientThread.join();