Просмотр исходного кода

Close command

closes connection to the client
anon 5 лет назад
Родитель
Сommit
a643fc3ef2
1 измененных файлов с 13 добавлено и 0 удалено
  1. 13 0
      daemon/src/Server.cpp

+ 13 - 0
daemon/src/Server.cpp

@@ -191,6 +191,19 @@ void con_handler::handle_read_command(const boost::system::error_code &err,
                            boost::bind(&con_handler::handle_read_command,
                                        shared_from_this(), placeholders::error,
                                        placeholders::bytes_transferred));
+    } else if (root["command"].compare("close") == 0) {
+      answer["command"] = "close";
+      answer["response"] = "bye";
+      const std::string answerString = Json::writeString(stringBuilder, answer);
+
+      // send answer
+      sock.async_write_some(buffer(answerString, max_length),
+                            boost::bind(&con_handler::handle_write,
+                                        shared_from_this(), placeholders::error,
+                                        placeholders::bytes_transferred));
+
+      // close connection
+      sock.close();
     } else {
       // TODO handle error