-
Notifications
You must be signed in to change notification settings - Fork 1
Neytrinoo exam 7 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: neytrinoo_exam_4
Are you sure you want to change the base?
Neytrinoo exam 7 #11
Conversation
…to boost_asio_backend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Исправляйте замечания и коммититьте в main
/* | ||
* Структура с колбеками, которые будут вызываться после успешного чтения и записи соответственно. | ||
*/ | ||
struct ServerConnectionCallbacks { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Обычно вместо этого делают интерфейс
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не увлекайтесь rvalue, копирование 20 байт быстрая операция, а вот передать константную строку вы уже не сможете
|
||
void read(); | ||
|
||
void readHandler(boost::system::error_code &err, size_t bytes_transferred); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
по-моему в колбеке const
#include <condition_variable> | ||
#include <atomic> | ||
|
||
#define BUFFER_LENGTH 1024 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constexpr int BUFFER_LENGTH = 1024; забудьте про макросы и define
#include <atomic> | ||
|
||
#define BUFFER_LENGTH 1024 | ||
#define END_STR "\r\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string или string_view
std::cerr << "delete ServerConnection" << std::endl; | ||
(*pos)->stop(); | ||
connections_.erase(pos); | ||
} catch (...) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
нехорошо игнорировать ошибки
} | ||
|
||
SharedDocumentServer::~SharedDocumentServer() { | ||
delete documentCommandBus_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unqiue_ptr, удалять руками очень опасно
IManageCommand::IManageCommand(command_t type_command) { | ||
switch (type_command) { | ||
case GET_DOCUMENT: | ||
letter_ = new GetDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new delete плохая практика, unique_ptr
return false; | ||
} | ||
|
||
std::shared_ptr<SharedDocumentServer> shared_document( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
заведите интерфейс
No description provided.