-
Notifications
You must be signed in to change notification settings - Fork 26
Зубаков Алексей. Задание 1 #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
Conversation
|
Не собирается |
h31
left a comment
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 namespace operations; | ||
|
|
||
| struct Server { |
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, если по факту это класс?
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.
Потому что мне лень писать public модификатор. По-моему, это вкусовщина.
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?
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 - это когда первичны данные, и есть некоторое количество кода для работы с ними (пример: точка с двумя координатами). class - когда первичен код, и есть некоторое количество полей для его работы.
Это был вопрос, а не замечание. Мне было вполне достаточно объяснения. Вкусовщина - да, поэтому и не замечание.
| std::shared_ptr<Operation> operation(parseRequest(socket)); | ||
| auto callback = [&]() { | ||
| int32_t result = operation.get()->evaluate(); | ||
| server.get()->sendResponse(socket, operation.get()->getType(), result); |
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.
Если перенести метод в класс RequestHandler, то не понадобится передавать ссылку на server.
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.
Мб, но кажется, что это не очень существенно. С вашего позволения оставлю как есть
| }; | ||
| std::async(std::launch::async, callback); | ||
| } catch (const std::exception &e) { | ||
|
|
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 execute() { | ||
| int clientSocket; | ||
| struct sockaddr_in address; | ||
| int opt = 1; |
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.
¯\_(ツ)_/¯
| operations::Operation *parseRequest(const int socket) { | ||
| std::unique_ptr<char[]> buffer(new char[REQUEST_SIZE]); | ||
|
|
||
| const ssize_t &ssize = read(socket, buffer.get(), REQUEST_SIZE); |
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.
Что произойдет, если read считает не всё сообщение целиком, а только часть?
| struct Operation { | ||
| Operation(Type type) : type(type) {} | ||
|
|
||
| virtual int32_t evaluate() const; |
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.
Почему именно int32_t? Объясните свой выбор.
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.
Во избежание вопросов про гарантии на то, что ос/компилятор, на которых будут запущены/скомпилированы клиент и сервер, обязательно используют одинаковый floating point encoding, например, IEEE-754. Насколько мне известно, в стандарте c++ это не специфицировано. Поэтому пересылка float -- такая себе затея, если нет какого-то конкретного протокола сериализации, сочинять велосипед не хочу.
В задании также не говорилось о том, что вычисления должны быть не целочисленными, поэтому никаких проблем не вижу.
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.
Если вопрос про почему не int, а int32_t, то ответ, по-моему, очевиден: не на всех платформах int 32-битный
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.
Тут скорее вопрос про то, почему не int64_t. Аргумент по поводу float и способов кодирования абсолютно уместный, согласен с ним.
| case Div: | ||
| return new operations::Division(arg1, arg2); | ||
| default: | ||
| perror(""); |
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.
Доделаю
| cmake_minimum_required(VERSION 3.12) | ||
| project(networks-labs) | ||
|
|
||
| set(TBB_DIR lib/tbb) |
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.
Где именно в вашем проекте используется TBB?
|
Принято. Оценка 9. Жду выполнения части, которая касается клиента (дедлайн уже давно прошел). |
No description provided.