Skip to content

Neytrinoo exam 4#9

Open
a-badin wants to merge 3 commits intomasterfrom
neytrinoo_exam_4
Open

Neytrinoo exam 4#9
a-badin wants to merge 3 commits intomasterfrom
neytrinoo_exam_4

Conversation

@a-badin
Copy link
Collaborator

@a-badin a-badin commented Dec 11, 2021

No description provided.

class BaseClient {
public:
BaseClient(boost::asio::io_service &service,
std::function<void(std::string command, BaseClient *this_client)> command_handler,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::string&


#include "Settings.h"

class BaseClient {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Родительский класс без виртуального деструктора - это очень грубая ошибка, которая ведет к утечке памяти и ресурсов

virtual void readCommand();

boost::asio::ip::tcp::socket sock_;
std::function<void(std::string command, BaseClient *this_client)> commandHandler_;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на такие объявления лучше сделать 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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

очень сложная будет инициализация объекта с 3 лямбдами внутри, сделайте сеттеры отдельно или интерфейс на все 3 функции сразу

enum {
SHARING_COMMAND = 0x01,
GET_DOCUMENT = 0x02
} command_t;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вы объявили не тип, а переменную анонимного типа

}

TEST_F(TestServer, test) {
std::strcpy(buf, SHARING_DOCUMENT_COMMAND);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

но ведь он может быть никогда не подключится

return;
}

std::cerr << "Accept client" << std::endl;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавлять клиентов в вектор нужно тут

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];
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_write_some не гарантирует полную передачу данных, он передает сколько сможет не блокируясь

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants