Skip to content

Commit

Permalink
修复sql_debug没有发送消息终结符的问题 (#298)
Browse files Browse the repository at this point in the history
### What problem were solved in this pull request?

Problem:
sql-debug的消息没有发送最终的消息终结符,并且消息是在消息终结符发送后发送的。

### What is changed and how it works?
消息终结符统一在write_result最后发送,其它函数不再发送
  • Loading branch information
hnwyllmm authored Nov 7, 2023
1 parent 7000de5 commit 5c5dc70
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/observer/net/plain_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ RC PlainCommunicator::write_state(SessionEvent *event, bool &need_disconnect)
snprintf(buf, buf_size, "%s > %s\n", strrc(sql_result->return_code()), state_string.c_str());
}

RC rc = writer_->writen(buf, strlen(buf) + 1);
RC rc = writer_->writen(buf, strlen(buf));
if (OB_FAIL(rc)) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
need_disconnect = true;
Expand Down Expand Up @@ -159,7 +159,18 @@ RC PlainCommunicator::write_result(SessionEvent *event, bool &need_disconnect)
{
RC rc = write_result_internal(event, need_disconnect);
if (!need_disconnect) {
(void)write_debug(event, need_disconnect);
RC rc1 = write_debug(event, need_disconnect);
if (OB_FAIL(rc1)) {
LOG_WARN("failed to send debug info to client. rc=%s, err=%s", strrc(rc), strerror(errno));
}
}
if (!need_disconnect) {
rc = writer_->writen(send_message_delimiter_.data(), send_message_delimiter_.size());
if (OB_FAIL(rc)) {
LOG_ERROR("Failed to send data back to client. ret=%s, error=%s", strrc(rc), strerror(errno));
need_disconnect = true;
return rc;
}
}
writer_->flush(); // TODO handle error
return rc;
Expand Down Expand Up @@ -276,14 +287,6 @@ RC PlainCommunicator::write_result_internal(SessionEvent *event, bool &need_disc
sql_result->set_return_code(rc);
return write_state(event, need_disconnect);
} else {

rc = writer_->writen(send_message_delimiter_.data(), send_message_delimiter_.size());
if (OB_FAIL(rc)) {
LOG_ERROR("Failed to send data back to client. ret=%s, error=%s", strrc(rc), strerror(errno));
sql_result->close();
return rc;
}

need_disconnect = false;
}

Expand Down

0 comments on commit 5c5dc70

Please sign in to comment.