1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 18:34:25 +01:00

Added response to subscription

This commit is contained in:
Ralf Ramsauer 2015-09-25 00:04:02 +02:00
parent b07c0e8f54
commit 80d8610559

View File

@ -105,20 +105,20 @@ static void session(tcp::socket &&sock)
l(response.message, LogLevel::warning); l(response.message, LogLevel::warning);
goto out; goto out;
} }
response.code = Response::Code::Success;
response .message = "";
sock.write_some(boost::asio::buffer(response.toJson()),
error);
while (run) { while (run) {
std::unique_lock<std::mutex> lock(mutex); std::unique_lock<std::mutex> lock(mutex);
onClientMessage.wait(lock); onClientMessage.wait(lock);
if (sock.is_open() == false) {
goto out;
}
if (run) { if (run) {
sock.write_some(boost::asio::buffer(logic->getClientMessage().toJson())); sock.write_some(boost::asio::buffer(logic->getClientMessage().toJson()));
} }
}; };
response.code = Response::Code::Success;
} else { } else {
response.code = Response::Code::UnknownCommand; response.code = Response::Code::UnknownCommand;
response.message = "Received unknown command " + command; response.message = "Received unknown command " + command;
@ -126,7 +126,6 @@ static void session(tcp::socket &&sock)
} }
out: out:
if (sock.is_open()) {
sock.write_some(boost::asio::buffer(response.toJson()), sock.write_some(boost::asio::buffer(response.toJson()),
error); error);
if (error == boost::asio::error::eof) if (error == boost::asio::error::eof)
@ -134,7 +133,6 @@ static void session(tcp::socket &&sock)
else if (error) else if (error)
throw boost::system::system_error(error); throw boost::system::system_error(error);
} }
}
catch (const std::exception &e) { catch (const std::exception &e) {
std::string message = "Exception in session " + remoteAddress.to_string() std::string message = "Exception in session " + remoteAddress.to_string()
+ ":" + std::to_string(remotePort) + " : " + e.what(); + ":" + std::to_string(remotePort) + " : " + e.what();