Skip to content

Conversation

@ottergottaott
Copy link

No description provided.

@h31
Copy link
Owner

h31 commented Feb 11, 2019

Не собирается
https://pastebin.com/bgg3X9yA

Copy link
Owner

@h31 h31 left a 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 {
Copy link
Owner

Choose a reason for hiding this comment

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

Почему struct, если по факту это класс?

Copy link
Author

@ottergottaott ottergottaott Feb 12, 2019

Choose a reason for hiding this comment

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

Потому что мне лень писать public модификатор. По-моему, это вкусовщина.

Copy link
Author

Choose a reason for hiding this comment

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

Даже стало интересно, а чем плохо писать struct?

Copy link
Owner

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

Choose a reason for hiding this comment

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

Если перенести метод в класс RequestHandler, то не понадобится передавать ссылку на server.

Copy link
Author

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) {

Copy link
Owner

Choose a reason for hiding this comment

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

Пустой обработчик

Copy link
Author

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;
Copy link
Owner

Choose a reason for hiding this comment

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

Эта переменная где-либо используется?

Copy link
Author

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

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;
Copy link
Owner

Choose a reason for hiding this comment

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

Почему именно int32_t? Объясните свой выбор.

Copy link
Author

@ottergottaott ottergottaott Feb 12, 2019

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 -- такая себе затея, если нет какого-то конкретного протокола сериализации, сочинять велосипед не хочу.

В задании также не говорилось о том, что вычисления должны быть не целочисленными, поэтому никаких проблем не вижу.

Copy link
Author

@ottergottaott ottergottaott Feb 12, 2019

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-битный

Copy link
Owner

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("");
Copy link
Owner

Choose a reason for hiding this comment

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

Есть смысл уведомить клиента, если произошла какая-то ошибка (например, пришли некорректные данные).

Copy link
Author

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)
Copy link
Owner

Choose a reason for hiding this comment

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

Где именно в вашем проекте используется TBB?

GrigoryBartosh pushed a commit to GrigoryBartosh/hse06_NetworksLab2019HSE that referenced this pull request Feb 19, 2019
GrigoryBartosh pushed a commit to GrigoryBartosh/hse06_NetworksLab2019HSE that referenced this pull request Feb 19, 2019
@h31
Copy link
Owner

h31 commented Mar 6, 2019

Принято. Оценка 9. Жду выполнения части, которая касается клиента (дедлайн уже давно прошел).

@h31 h31 closed this Mar 6, 2019
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