Skip to content

Conversation

@SashaOrlova
Copy link

No description provided.

@SashaOrlova SashaOrlova changed the title Bug tracker Киракосян, Орлова, багтрекер Feb 20, 2019
/* Now connect to the server */
if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0) {
std::cerr << "ERROR connecting\n";
exit(1);
Copy link
Owner

Choose a reason for hiding this comment

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

Желательно, конечно, не делать exit прямо посреди I/O логики, завершением программы должен управлять отдельный слой кода.

std::string client::getString() {
int length = getNum();
char* buf = new char[length + 1];
int n = read(sockfd, buf, length);
Copy link
Owner

Choose a reason for hiding this comment

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

char* buf = new char[length + 1];
int n = read(sockfd, buf, length);
buf[length] = '\0';
std::string ans(buf);
Copy link
Owner

Choose a reason for hiding this comment

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

Если вы знаете размер посылки, то можно сразу создать std::string ans нужной длины и передавать and.data() в read.

std::cout << "You not authorize\n";
break;
}
case CHECK_RIGHTS: {
Copy link
Owner

Choose a reason for hiding this comment

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

Слишком много похожего кода. т.е. дублирование

uint32_t bugId, verificationCode;
readInt32(sock_fd, bugId);
readInt32(sock_fd, verificationCode);
if (!client.isAuthorized()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Авторизация проверяется в нескольких функциях, поэтому, чтобы убрать дублирование, можно было бы вынести её куда-нибудь в process_client, чтобы проверять только из одной функции.

_bugs_mutex.lock();
if (_bugs.find(bugId) == _bugs.end()) {
_bugs_mutex.unlock();
std::cout << "Developer with id " << client.user.id << " tried to fix non existing bug with id " << bugId << "\n";
Copy link
Owner

Choose a reason for hiding this comment

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

Обратите внимание, что у вас очень часто встречается комбинания "вывели строку на экран, отправили число, отправили ещё число". Вполне кандидан на выделение в отдельную функцию.

} else if (_bugs[bugId].status == Bug::BugStatus::QA){
if (verificationCode == 0) {
_bugs[bugId].status = Bug::BugStatus::NEW;
_bugs_mutex.unlock();
Copy link
Owner

Choose a reason for hiding this comment

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

Можно использовать lock guard, чтобы чуточку упростить код и повысить его надежность.

}
char buf[length + 1];
buf[length] = '\0';
ssize_t n = read(sock_fd, buf, length);
Copy link
Owner

Choose a reason for hiding this comment

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

См. замечание к std::string client::getString().

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.

3 participants