Conversation
| class BaseClient { | ||
| public: | ||
| BaseClient(boost::asio::io_service &service, | ||
| std::function<void(std::string command, BaseClient *this_client)> command_handler, |
There was a problem hiding this comment.
const std::string&
|
|
||
| #include "Settings.h" | ||
|
|
||
| class BaseClient { |
There was a problem hiding this comment.
Родительский класс без виртуального деструктора - это очень грубая ошибка, которая ведет к утечке памяти и ресурсов
| virtual void readCommand(); | ||
|
|
||
| boost::asio::ip::tcp::socket sock_; | ||
| std::function<void(std::string command, BaseClient *this_client)> commandHandler_; |
There was a problem hiding this comment.
на такие объявления лучше сделать using
| public: | ||
| DocumentClient(boost::asio::io_service &service, | ||
| std::function<void(std::string command, BaseClient *this_client)> command_handler, | ||
| std::function<void(BaseClient *client)> on_delete, |
There was a problem hiding this comment.
очень сложная будет инициализация объекта с 3 лямбдами внутри, сделайте сеттеры отдельно или интерфейс на все 3 функции сразу
| enum { | ||
| SHARING_COMMAND = 0x01, | ||
| GET_DOCUMENT = 0x02 | ||
| } command_t; |
There was a problem hiding this comment.
вы объявили не тип, а переменную анонимного типа
| } | ||
|
|
||
| TEST_F(TestServer, test) { | ||
| std::strcpy(buf, SHARING_DOCUMENT_COMMAND); |
There was a problem hiding this comment.
std::string buf = SHARING_DOCUMENT_COMMAND + END_STR;
| }, | ||
| [this](BaseClient *client) { return this->deleteClient(client); }, | ||
| [this](std::string &token) { return this->checkAuthToken(token); })); | ||
| clients_.push_back(client); |
There was a problem hiding this comment.
но ведь он может быть никогда не подключится
| return; | ||
| } | ||
|
|
||
| std::cerr << "Accept client" << std::endl; |
There was a problem hiding this comment.
добавлять клиентов в вектор нужно тут
| boost::asio::ip::tcp::socket sock_; | ||
| std::function<void(std::string command, BaseClient *this_client)> commandHandler_; | ||
| std::function<void(BaseClient *client)> onDelete_; | ||
| char readBuf_[BUFFER_LENGTH]; |
There was a problem hiding this comment.
std::array или std::string, с reserve в кострукторе
| for (int i = 0; i < command.length(); ++i) { | ||
| sendBuf_[i] = command[i]; | ||
| } | ||
| sock_.async_write_some(boost::asio::buffer(sendBuf_, command.length()), [this_obj = this](auto &&PH1, auto &&PH2) { |
There was a problem hiding this comment.
async_write_some не гарантирует полную передачу данных, он передает сколько сможет не блокируясь
No description provided.