-
Notifications
You must be signed in to change notification settings - Fork 2
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
Server friends #1
base: server_friends
Are you sure you want to change the base?
Conversation
…щносятми, роут сервер
// Тест парсера Json | ||
|
||
TEST(Test_parser, parse_test_1) { | ||
tcp_network::ParseJson parser; |
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.
у тебя класс ParseJson
имеет 2 статических методы, для вызова статических методов нет необходимости создавать экземпляр класса, так как их можно вызвать напрямую
|
||
class ParseJson { | ||
public: | ||
explicit ParseJson() = default; |
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.
а можно было обойтись дефолтным конструктором?
# - sudo wget https://github.com/Kitware/CMake/releases/download/v3.19.1/cmake-3.19.1.tar.gz | ||
# - sudo tar -zxvf cmake-3.19.1.tar.gz && cd cmake-3.19.1 | ||
# - sudo ./bootstrap && sudo make && sudo make install |
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.
Из рабочей версии стоит удалить закомменченный код
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.
из финальной версии весь закомменченный и отладочный код будет убран
else() | ||
set(CMAKE_CXX_STANDARD 17) | ||
endif() | ||
set(CMAKE_CXX_FLAGS "-lpqxx -lpq") |
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.
Лучше подключать библиотеки не через флаги, а через target_link_libraries
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.
исправлю на поиск через find_package
using namespace boost::asio; | ||
|
||
|
||
class Client { |
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.
У клиента будет бесконечный цикл, неясно, как корректно завершить работу с клиентом
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.
да, есть сейчас такой недочёт. исправлю
|
||
|
||
boost::asio::write(socket, boost::asio::buffer(add_request.c_str(), add_request.size())); | ||
std::cout << "Запрос отправлен" << std::endl; |
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.
Здесь и далее стоило выводить отладочную информацию в логи
|
||
using boost::asio::ip::tcp; | ||
|
||
const int max_length = 2024; |
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.
Почему именно такое значение?
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.
используется для чтения присланного клиентом сообщения в сишный буфер такого же размера
} | ||
} | ||
|
||
void Session::send_response(std::string& respones) { |
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.
При каждой отправке сообщения создается новый клиент, возможно стоило не разрывать соединение
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.
да, такая проблема есть. но необходимость поддерживать открытое соединение между всеми серверами в нашей сети сильно бы усложнило логику
#else | ||
BOOST_LOG_TRIVIAL(error) << e.what(); | ||
#endif | ||
return {0, 0}; |
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.
Выглядит очень странно, непонятно, что означает {0, 0}
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.
показатель того, что к нам пришли несуществующие порт и ip
auto iter = request.find('\n'); | ||
requsts.insert({"destination", request.substr(0, iter)}); | ||
request.erase(0, iter + 1); | ||
iter = request.find('\n'); | ||
requsts.insert({"priority", request.substr(0, iter)}); | ||
request.erase(0, iter + 1); | ||
iter = request.find('\n'); | ||
requsts.insert({"type", request.substr(0, iter)}); | ||
request.erase(0, iter + 2); |
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.
Возможно стоило вынести это в отдельные/отдельную функцию, что сделает логику работы понятнее
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.
может быть, но эта функция и так отвечает за парсинг
|
||
#include "friends_data_base.h" | ||
|
||
int main(int argc, char **argv) { |
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
@@ -0,0 +1,324 @@ | |||
// |
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.
Для каждого теста поднимается отдельный эхо-сервер, выглядит не очень оптимально
Uml-диаграмма Сервера Friends