Conversation
…to boost_asio_backend
a-badin
left a comment
There was a problem hiding this comment.
Исправляйте замечания и коммититьте в main
| /* | ||
| * Структура с колбеками, которые будут вызываться после успешного чтения и записи соответственно. | ||
| */ | ||
| struct ServerConnectionCallbacks { |
There was a problem hiding this comment.
Обычно вместо этого делают интерфейс
struct IServerListener {
virtual onReadCb(std::string &&) = 0;
virtual onWriteCb(boost::system::error_code &err) = 0;
};
|
|
||
| class ServerConnection { | ||
| public: | ||
| ServerConnection(std::string &&url, int port, ServerConnectionCallbacks &&callbacks); |
There was a problem hiding this comment.
не увлекайтесь rvalue, копирование 20 байт быстрая операция, а вот передать константную строку вы уже не сможете
|
|
||
| void read(); | ||
|
|
||
| void readHandler(boost::system::error_code &err, size_t bytes_transferred); |
There was a problem hiding this comment.
по-моему в колбеке const
| #include <condition_variable> | ||
| #include <atomic> | ||
|
|
||
| #define BUFFER_LENGTH 1024 |
There was a problem hiding this comment.
constexpr int BUFFER_LENGTH = 1024; забудьте про макросы и define
| #include <atomic> | ||
|
|
||
| #define BUFFER_LENGTH 1024 | ||
| #define END_STR "\r\n" |
There was a problem hiding this comment.
const std::string или string_view
| std::cerr << "delete ServerConnection" << std::endl; | ||
| (*pos)->stop(); | ||
| connections_.erase(pos); | ||
| } catch (...) { |
There was a problem hiding this comment.
нехорошо игнорировать ошибки
| } | ||
|
|
||
| SharedDocumentServer::~SharedDocumentServer() { | ||
| delete documentCommandBus_; |
There was a problem hiding this comment.
unqiue_ptr, удалять руками очень опасно
| IManageCommand::IManageCommand(command_t type_command) { | ||
| switch (type_command) { | ||
| case GET_DOCUMENT: | ||
| letter_ = new GetDocument(); |
There was a problem hiding this comment.
new delete плохая практика, unique_ptr
| return false; | ||
| } | ||
|
|
||
| std::shared_ptr<SharedDocumentServer> shared_document( |
There was a problem hiding this comment.
auto shared_document = std::make_shared(...), экономит 1 алокацию памяти
|
|
||
| SharedDocumentServer::SharedDocumentServer(boost::asio::io_context &service) : server_(start_since_port++, service, | ||
| ServerCallbacks{ | ||
| [this](std::shared_ptr<Connection> connection) { |
There was a problem hiding this comment.
заведите интерфейс
No description provided.