Skip to content

feat 3hw: tcp client + server#3

Open
axel36 wants to merge 6 commits into
masterfrom
3hw
Open

feat 3hw: tcp client + server#3
axel36 wants to merge 6 commits into
masterfrom
3hw

Conversation

@axel36
Copy link
Copy Markdown
Owner

@axel36 axel36 commented Nov 21, 2020

Тестировал через net cat

@axel36 axel36 requested review from Kapitonov and a-badin November 21, 2020 20:04
Copy link
Copy Markdown
Collaborator

@Kapitonov Kapitonov left a comment

Choose a reason for hiding this comment

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

Если предполагается реальное использование библиотеки, то у вас довольно моного логгирования в коде. Есть вероятность, что большую часть времени ваше приложение будет им и заниматься.


bool Connection::IsOpen() const { return socket_.isValid(); }

void Connection::LogErrorAndThrow() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Название функции не отображает её сути.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Почему?
она же как раз и делает то, что написанно?

Comment thread lib/hw_3_tcp/src/connection.cpp Outdated

void Connection::LogErrorAndThrow() {

socket_ = desc::Descriptor{};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А socket_.close() не тоже самое сделает?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Поправил

Comment thread lib/hw_3_tcp/src/server.cpp Outdated
}

void Server::LogErrorAndThrow() {
server_socket_ = desc::Descriptor{};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А sercver_socket_.close() не тоже самое сделает?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

поправил

Comment thread lib/hw_3_tcp/include/tcp.hpp Outdated
void Connect(const std::string &addr, int port);
};

class Server {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Реализация в разных файлах, давайте и объявления разнесем.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Разнес

Comment thread lib/hw_3_tcp/src/connection.cpp
Comment thread lib/hw_3_tcp/src/server.cpp Outdated
client_fd = desc::Descriptor{::accept(
*server_socket_, reinterpret_cast<sockaddr *>(&client_sock_addr), &s)};
} catch (const desc::DescriptorError &err) {
LogErrorAndThrow();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А в этом месте точно надо закрывать соккет сервера?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

да, не стоит

Comment thread lib/hw_3_tcp/src/server.cpp
@axel36
Copy link
Copy Markdown
Owner Author

axel36 commented Nov 26, 2020

Если предполагается реальное использование библиотеки, то у вас довольно моного логгирования в коде. Есть вероятность, что большую часть времени ваше приложение будет им и заниматься.

Так это все Debug уровень логирования, мы при инициализации программы можем установить уровень логгера в warn или Info и будет куда меньше логов, и вообще, я считаю, что логи это очень хорошо, если я буду пользоваться библиотекой, которая может полностью отлогировать себя при моем желании я буду очень рад)

@axel36 axel36 requested a review from Kapitonov November 27, 2020 15:28
Copy link
Copy Markdown
Collaborator

@Kapitonov Kapitonov left a comment

Choose a reason for hiding this comment

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

Можно сливать после исправления.


void Close();

size_t Read(char *, size_t);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

В других функциях вы пишете названия переменных.

ssize_t bytes_read = ::read(*socket_, data, len);

if (bytes_read < 0) {
LogErrorAndThrow();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Лучше кинуть исключение.

ssize_t bytes_wrote = ::write(*socket_, data, len);

if (bytes_wrote < 0) {
LogErrorAndThrow();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Кинуть исключение

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